注意:函数
ca.set(2011, 12, 2); 2012-01-02spa
ca.set(2011, 0, 2); 2011-01-02orm
日期 get
ca.set(2011, 2, 1); 2011-03-01date
ca.set(2011, 2, 31); 2011-03-31im
ca.set(2011, 2, 32); 2011-04-01时间
ca.set(2011, 2, 0); 2011-02-28co
ca.set(2011, 2, -1); 2011-02-27block
0.经常使用函数:new
获取本月最后一天
ca.set(Calendar.DAY_OF_MONTH,ca.getActualMaximum(Calendar.DAY_OF_MONTH));
获取本月第一天
cal_1.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
cale.set(Calendar.DAY_OF_MONTH,0);// 获去前月最后一天
1. 减一个月'
这里7月 不要超过 32天
ca.set(2011, 6, 31);// 月份是从0开始的,因此11表示12月
dateToFormatChar(ca.getTime());
int i=-1;
ca.add(Calendar.MONTH, i);// 月份减1显示:
2011-07-31
2011-06-30
2011-05-30
2011-04-30
2011-03-30
2011-02-28
2011-01-28
2.加一个月
ca.set(2011, 6, 31);// 月份是从0开始的,因此11表示12月
dateToFormatChar(ca.getTime());
int i=1;
ca.add(Calendar.MONTH, i);// 月份减1
dateToFormatChar(ca.getTime());
ca.add(Calendar.MONTH, i);// 月份减1
dateToFormatChar(ca.getTime());
ca.add(Calendar.MONTH, i);// 月份减1
dateToFormatChar(ca.getTime());
ca.add(Calendar.MONTH, i);// 月份减12011-07-31
2011-08-31
2011-09-30
2011-10-30
2011-11-30
2011-12-30
2012-01-30
2012-02-29
2012-03-29
3.日期 加一天
ca.set(2011, 6, 31);// 月份是从0开始的,因此11表示12月
dateToFormatChar(ca.getTime());
int i=1;
ca.add(Calendar.DATE, i);// 月份减1
dateToFormatChar(ca.getTime());2011-07-31
2011-08-01
2011-08-02
2011-08-03
2011-08-04
3.日期 减一天
ca.set(2011, 6, 1);// 月份是从0开始的,因此11表示12月
dateToFormatChar(ca.getTime());
int i=-1;
ca.add(Calendar.DATE, i);// 月份减1
dateToFormatChar(ca.getTime());
ca.add(Calendar.DATE, i);// 月份减12011-07-01
2011-06-30
2011-06-29
2011-06-28
2011-06-27//ca.setTime(new Date()); // 设置时间为当前时间
ca.set(2011, 6, 0);// 月份是从0开始的,因此11表示12月
dateToFormatChar(ca.getTime());
int i=-1;
ca.add(Calendar.DATE, i);// 月份减1
dateToFormatChar(ca.getTime());2011-06-30 2011-06-29