calendar.get(Calendar.MONTH)
如果是1月,返回的是0。它下标从0开始,所以转到实际的要加1。下面这段代码,就看出来了,如果是12月,c.get(Calendar.MONTH)返回的是11。String s = "20121201";
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
Date date = sdf.parse(s);
Calendar c = Calendar.getInstance();
c.setTime(date); System.out.println(c.get(Calendar.MONTH));

解决方案 »

  1.   

    因为月份跟年、日是不一样的,英文月份不是用阿拉伯数字表示的,而跟罗马数字有关,但是存在很多人为因素,本就不是一一对应的。
    就是一个习惯问题吧,好像就只有Calendar类是这样的,其他时间类是从1开始的。
      

  2.   


    LZ好好读读JDK API就知道原因了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. 注意红色的部分,Calendar的月份是从0开始计算的,0代表January,以此类推6代表July即我们的7月份。
      

  3.   

    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.  注意红色的部分,Calendar的月份是从0开始计算的,0代表January,以此类推6代表July即我们的7月份。
    good~
      

  4.   

    在格里高利历和罗马儒略历中一年中的第一个月是 JANUARY,它为 0;所以用整数显示的月份会出现这种情况。加1就好了。