java.util.calendar中的默认字段值错误 [英] Wrong default fields values in java.util.calendar

查看:163
本文介绍了java.util.calendar中的默认字段值错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建 java.util.Calendar 类的实例:

Calendar rightNow = Calendar.getInstance();

getInstance() $ c> Calendar 使用默认时区和区域设置...它现在在波兰的20:22 1.11.2012,但是当我打印 rightNow field out,结果是错误的:

getInstance() gets a Calendar using the default time zone and locale... Its 20:22 1.11.2012 in Poland right now, but when I print rightNow field out, the result is wrong:

System.out.print(rightNow.get(Calendar.MONTH));
result: 10.

System.out.print(rightNow.get(Calendar.DAY_OF_MONTH));
result: 1.

System.out.print(rightNow.get(Calendar.DATE));
result: 1.

我假设12月份 YEAR 字段也会出错。

I supose that in December the YEAR field will also be wrong. Can somebody explain that to me?

推荐答案

从0开始使用日历不是从1开始

Month starts from 0 when you use calendar not from 1

根据 javadoc


表示月份的get和set字段号。这是特定于日历的值。一年中的第一个月在格里高利和朱利安日历是JANUARY是0;最后一次取决于一年中的月数。

Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year in the Gregorian and Julian calendars is JANUARY which is 0; the last depends on the number of months in a year.

这篇关于java.util.calendar中的默认字段值错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆