- import java.util.*;
- class CalendarDemo
- {
- public static void main(String[] args)
- {
- Calendar c = Calendar.getInstance();
- c.set(2014,2,28);//2014年3月28日
- c.add(Calendar.DAY_OF_MONTH,-1);
-
- printCalendar(c);
-
-
- }
- public static void printCalendar(Calendar c)
- {
- String[] mons = {"一月","二月","三月","四月",
- "五月","六月","七月","八月",
- "九月","十月","十一月","十二月"};
- int index = c.get(Calendar.MONTH);
-
-
- String[] weeks = {"","星期日","星期一","星期二",
- "星期三","星期四","星期五","星期六"};//为什么要加一个空字符串
- int index1 = c.get(Calendar.DAY_OF_WEEK);
-
- sop(c.get(Calendar.YEAR)+"年");
- sop(mons[index]);
- sop(c.get(Calendar.DAY_OF_MONTH)+"日");
- sop(weeks[index1]);
- }
- public static void sop(Object obj)
- {
- System.out.println(obj);
- }
- }
- 建立星期的字符串数组时,为什么要加上一个空的字符串,不是很理解!
复制代码 |