如题:
    在java中使用Calendar获取日期中的月时,为什么总是要加1才是正常的月份呢?

解决方案 »

  1.   

    use constans like Calendar.JANUARY
      

  2.   

    因为它如同数组的INDEX是从0开始一样,一月份是0所以你要加1
      

  3.   

    public static final int MONTH
    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.
      

  4.   

    学英语的时候 好像听老师说过 老外叫二楼做一楼 同理 同理 hehe
      

  5.   

    当初编java的人规定的,你可以继承一下那个类,让它从1开始,以后就用你自已的类不就可以了
      

  6.   

    同数组的INDEX是从0开始一样,一月份是0所以你要加1
      

  7.   

    在英语里面,January和1没有什么必然的联系,不像汉语里面一月和数字1关联的那么密切。
    同样的还有代表星期一的Monday。
      

  8.   

    看看Calendar源代码:package java.util;/**
     * 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中?明摆着有偏见。