如题:
在java中使用Calendar获取日期中的月时,为什么总是要加1才是正常的月份呢?
在java中使用Calendar获取日期中的月时,为什么总是要加1才是正常的月份呢?
解决方案 »
- 自己做的JXComboButton,但是popupMenu总是能不能更换皮肤,请教
- Unhandled Exception thrown: class java.lang.NullPointerException
- 文件通道最终将取代流操作?
- 高分 求解析 XML字符串的方法,解决即结贴
- 利用JNI 调用MessageBox 只闻其声不见其形
- 100分求工作流的流程自定义方式
- callback函数的问题
- java 正则表达式匹配字符串
- 100分求学“流”!流好难理解啊。谁能来讲解讲解吗?
- 一个自定义java2 Swing JTree的问题??很有挑战性!!
- Stack中的peek()方法的返回类型是什么啊?(JDK1.5)
- 关于《Thinking in Java》(java编程思想)
Field number for get and set indicating the month. This is a calendar-specific value. The first month of the year is JANUARY which is 0; the last depends on the number of months in a year.
同样的还有代表星期一的Monday。
* Calendar is an abstract base class for converting between
* a Date object and a set of integer fields such as
* YEAR, MONTH, DAY, HOUR,
* and so on.
...................................
* Subclasses of Calendar interpret a Date
* according to the rules of a specific calendar system. The platform
* provides one concrete subclass of Calendar:
* GregorianCalendar. Future subclasses could represent
* the various types of lunar calendars in use in many parts of the world.
......................................................
*/public abstract class Calendar implements Serializable, Cloneable {
......................... /**
* Value of the MONTH field indicating the
* first month of the year.
*/
public final static int JANUARY = 0;
/**
* Value of the MONTH field indicating the
* second month of the year.
*/
public final static int FEBRUARY = 1;
public final static int MARCH = 2;
public final static int APRIL = 3;
public final static int MAY = 4;
public final static int JUNE = 5;
public final static int JULY = 6;
public final static int AUGUST = 7;
public final static int SEPTEMBER = 8;
public final static int OCTOBER = 9;
public final static int NOVEMBER = 10;
public final static int DECEMBER = 11;
/**
* Value of the MONTH field indicating the
* thirteenth month of the year. Although GregorianCalendar
* does not use this value, lunar calendars(阴历) do.
*/
public final static int UNDECIMBER = 12; ................
}月份是可数的且固定的,所以被声明成了常量,但不明白为什么要从0开始声明。另外Calendar被做成抽象类就是为了让别人继承的,干嘛还要把格林高利历中的十二个月的定义放到Calendar中而不放到GregorianCalendar中?明摆着有偏见。