本帖最后由 陈培果 于 2014-5-10 21:55 编辑
- import java.util.*;
- /*
- Calendar 常见用法
- */
- class CalendarDemo2
- {
- public static void main(String[] args)
- {
- Calendar c= Calendar.getInstance();
- c.set(2012,11,1,1,1,1);//设置年月日
-
- printCalendar(c);
- }
- public static void printCalendar(Calendar c)
- {
- String[] mons={"一月","二月","三月","四月",
- "五月","六月","七月","八月",
- "九月","十月","十一月","十二月"};
- int index=c.get(Calendar.MONTH);
- String[] week={"","星期天","星期一","星期二","星期三","星期四","星期五","星期六"};
- int index1=c.get(Calendar.DAY_OF_WEEK);
- sop(c.get(Calendar.YEAR)+"年");
- //sop((c.get(Calendar.MONTH)+1)+"月");
- sop(mons[index]);
- sop(c.get(Calendar.DAY_OF_MONTH)+"日");
- //sop("星期"+c.get(Calendar.DAY_OF_WEEK));
- sop(week[index1]);
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
- /*
- c.set(2012,11,1);//设置年月日
- 为什么我写c.set(2012); c.set(2012,11); c.set(2012,11,1,1);都编译失败
- 但是我写c.set(2012,11,1,1,1);c.set(2012,11,1,1,1);编译通过
- 请问c.set();里面都可以写多少个整形,为什么?
- 求大神解答.
- */
复制代码
|