- /*Calendar 日历*/
- import java.util.*;
- class CalendarDemo
- {
- public static void main(String[] args)
- {
- Calendar c = Calendar.getInstance();
- // c.set(2013,8,9);//设定时间值
-
- c.add(Calendar.YEAR,2);//制定字段,加减时间量
- printCalendar(c);
- }
- public static void printCalendar(Calendar c)
- {
- String[] month = {"一月 ","二月 ","三月 ","四月 ",
- "五月 ","六月 ","七月 ","八月 ",
- "九月 ","十月 ","十一月 ","十二月 "};
- String[] week = {"","星期日","星期一","星期二",
- "星期三","星期四","星期五","星期六",};
- int index_month = c.get(Calendar.MONTH);
- int index_week = c.get(Calendar.DAY_OF_WEEK);//你这里是DAY_OF_MONTH(一个月的第几天)当然越界了,改成DAY_OF_WEEK即可
- sop(c.get(Calendar.YEAR)+"年");
- //sop((c.get(Calendar.MONTH)+1)+"月");
- sop(month[index_month]);
- sop(c.get(Calendar.DAY_OF_MONTH)+"日");
- //sop("星期"+c.get(Calendar.DAY_OF_WEEK));
- sop(week[index_week]);
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
复制代码 |