本帖最后由 蓝迪 于 2012-8-28 13:27 编辑
- import java.util.*;
- import java.text.*;
- class CalendarDemo
- {
- public static void main(String[] args)
- {
- Calendar c = Calendar.getInstance();
-
- String[] mons ={"1月","2月","3月","4月"
- ,"5月","6月","7月","8月"
- ,"9月","10月","11月","12月"};
- int index = c.get(Calendar.MONTH);//获取月份
- String[] weeks ={"","7","1","2","3","4","5","6"};
- int indexs = c.get(Calendar.DAY_OF_WEEK);//获取星期
- sop(c.get(Calendar.YEAR)+"年");
-
- sop(mons[index]);
- sop(c.get(Calendar.DAY_OF_MONTH)+"日");
- sop("星期"+weeks[indexs]);
-
- }
-
- }
复制代码 问:同样是查表法获取月份和日期,都是从0角标位开始查找
为什么获取月份的时候不需要前头加个空的元素,而获取日期需要加一个空元素 |