本文介紹了Calendar.Month 給出錯誤的輸出的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
限時送ChatGPT賬號..
我一直在使用 java.util
來表示所有日期和日歷.但我在這里面臨一個奇怪的問題.Calendar.MONTH
、Calendar.DAY_OF_MONTH
等都給出錯誤的輸出.但是當(dāng)我使用 Calendar.getTime()
時,我得到了正確的輸出.可能是什么問題?
I have been using java.util
for all date and calendar representations. But I am facing a strange problem here. Calendar.MONTH
, Calendar.DAY_OF_MONTH
, etc all give wrong outputs. But when I use Calendar.getTime()
, I get the right output. What might be the problem?
public class TestClass {
public static void main(String[] args) {
Calendar rightNow = Calendar.getInstance();
System.out.println(rightNow.MONTH);
System.out.println(rightNow.DAY_OF_MONTH);
System.out.println(rightNow.YEAR);
System.out.println(rightNow.getTime());
}
}
同樣的輸出是:
2
5
1
Tue Jan 22 10:31:44 GMT+05:30 2013
推薦答案
System.out.println(rightNow.MONTH);
System.out.println(rightNow.DAY_OF_MONTH);
System.out.println(rightNow.YEAR);
System.out.println(rightNow.getTime());
您正在打印日歷常量值.
You are printing Calendar constant values.
如果你想要值,你需要做 get....
If you want values, you need to do get....
例子:
System.out.println(rightNow.get(Calendar.MONTH));
閱讀 日歷 javadoc 了解更多信息.
Read Calendar javadoc for more information.
這篇關(guān)于Calendar.Month 給出錯誤的輸出的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!