本文介紹了Java 日歷對象減去一個月的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我正在嘗試通過這樣做來填充日歷對象:
I'm trying to fill a calendar object by doing this:
Date now = new Date(System.currentTimeMillis());
Calendar cal = Calendar.getInstance();
cal.setTime(now);
現(xiàn)在是 2013-11-26 但是當(dāng)我打印出來時
It is now 2013-11-26 but when I print out
cal.get(Calendar.MONTH)
它將返回 10.
我該如何解決這個問題?
How can I fix this?
推薦答案
你不需要修復(fù)它.這是 日歷
行為.
You need not to fix it. It's Calendar
behavior.
cal.get(Calendar.MONTH)
您正在使用當(dāng)前月份的 System.currentTimeMillis()
.
you are using System.currentTimeMillis()
that is the current month.
返回 10
,因為月份從 0
開始.所以 10 是第 11 個月.即 Nov
Return 10
because the months starts from 0
. So 10 is the 11th month. I.e Nov
0-Jan
1-Feb
-
-
這篇關(guān)于Java 日歷對象減去一個月的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!