以前用如下代码得到上一个月
/*
SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd");
Calendar c1 = Calendar.getInstance();
c1.set(Calendar.MONTH,c1.get(Calendar.MONTH)- 1);
String dstr = dtFormat.format(c1.getTime());
*/
今天突然发现不对,在日期为20080731时得到却是20080701
正确的方法应该为:
SimpleDateFormat dtFormat = new SimpleDateFormat("yyyyMMdd");
GregorianCalendar c1 = new GregorianCalendar();
c1.add(GregorianCalendar.MONTH,-1);
String dstr = dtFormat.format(c1.getTime());