- public static void main(String[] args) {
- Calendar c = Calendar.getInstance();
- printClendar(c);
- }
- public static void printClendar(Calendar c)
- {
- //查表法
- String[] mons = {"一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
-
- // String[] weeks = {"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
- String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
- int index = c.get(Calendar.MONTH);
- int indexx = c.get(Calendar.DAY_OF_WEEK);//比如今天是周二 那么实际indexx=3
-
- System.out.println(c.get(Calendar.YEAR)+"年");
- System.out.println(mons[index]);
- System.out.println(c.get(Calendar.DAY_OF_MONTH)+"日");
- System.out.println(weeks[indexx]);
- }
复制代码 接着我们来分析下:
我觉得要留意这么一点就可以了~你要知道~java是谁出的~丫的是老美那一群人!!唉~是我们中国就好了~哈哈!!!所以在时间上,尤其是日期上··你要跟上他们~那就是··你周一··他们周日··你周二··他们周一··也就是说~你的时间是要倒退一天的!!理解了这一点~你就很好理解
你可以看我的代码~就算不在前面加空格也是可以的~不过“周日”是摆在了第一位
这样就可以了:int indexx = c.get(Calendar.DAY_OF_WEEK)-1; 减一就可以了!
你试试~还有啥细节不太懂的可以问问~ |