本帖最后由 我叫MT 于 2014-1-6 15:56 编辑
- //获取任意年的二月有多少天
- import java.util.*;
- class CalendarDemo2
- {
- public static void main(String[] args)
- {
- Calendar c = Calendar.getInstance();
- c.set(2014,2,1);
- c.add(Calendar.MONTH,1);
- c.add(Calendar.DAY_OF_MONTH,-1);
- printCalendar(c);
- }
- public static void printCalendar(Calendar c)
- {
- String[] mons = {"","一月","二月","三月","四月","五月","六月","七月","八月","九月","十月","十一月","十二月"};
- String[] weeks = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};
- int index = c.get(Calendar.MONTH);
- 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);
- }
- }
复制代码 Dos演示
D:\myjava>java CalendarDemo2
2014年
二月
31日
星期一
求解怎么回事应该要的结果是28天才对啊
D:\myjava>
|