import java.util.*;
class CalendarDemo2
{
public static void main(String[] args)
{
Calendar c=Calendar.getInstance();
// c.set(2012,2,23);任意设置时间
c.add(Calendar.DAY_OF_MONTH,1);
printCalendar(c);
}
public static void printCalendar(Calendar c)
{
String[] mons={"一月","二月","三月","四月","五月","六月"
,"七月","八月","九月","十月","十一月"
,"十二月"};
String[] weeks={"星期一","星期二","星期三","星期四","星期五","星期六","星期天"};
int index=c.get(Calendar.MONTH);
int index2=c.get(Calendar.DAY_OF_WEEK);
System.out.println(c.get(Calendar.YEAR)+"年");
System.out.println(mons[index]);
System.out.println(weeks[index2]);
}
}
c.add(Calendar.DAY_OF_MONTH,1);当我在这里延迟时间的时候比如,现在10月,我+3个月,按照比老师的说法应该会自动跳转到下一年1月的,可是我的确是ArrayIndexOutOfBoundsException异常。我添加天的时候也是,现在31一号,我多添加一天,也不会跳转到11月1号!!求解。。。毕老师在操作的时候都能成功顺延,我的是问题出在哪里?
|