日期:2014-05-20 浏览次数:20858 次
public static void main(String[] args) {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
c.set(Calendar.YEAR, 2013);
c.set(Calendar.MONTH, 1);
c.set(Calendar.DATE, 3);
c.add(Calendar.MONTH, -2);
System.out.println(sdf.format(c.getTime()));
}
String startDateStr = "";
String endDateStr = "";
TimeZone tzES2 = TimeZone.getTimeZone("GMT+8");
Calendar calES2 = Calendar.getInstance(tzES2);
Calendar ca = Calendar.getInstance();
Date now = ca.getTime();
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
dateFormat.setCalendar(calES2);
ca.set(Calendar.DATE, ca.getActualMinimum(Calendar.DAY_OF_MONTH));//设置当前日期为当前月的第一天
now = ca.getTime();
startDateStr = dateFormat.format(now);
ca.set(Calendar.DATE, ca.getActualMaximum(Calendar.DAY_OF_MONTH));//设置当前日期为当前月的最后一天
now = ca.getTime();
endDateStr = dateFormat.format(now);
System.out.println(startDateStr);
System.out.println(endDateStr);
ca.add(Calendar.MONTH, -1);//设置日期为当前日期加上-1个月(即减去1个月)的日期。后面的操作同上