标签:
public static void main(String[] args) { // 展示过去12个月 Calendar calendar = Calendar.getInstance(); Date now = null; try { now = DateUtils.parseDate( DateFormatUtils.format(new Date(), "yyyy-MM"), "yyyy-MM"); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } calendar.setTime(now); for (int i = 0; i < 12; i++) { // 月份递减(不包含本月) calendar.add(Calendar.MONTH, -1); // 包含本月(此句提前) System.out.println(DateFormatUtils.format(calendar, "yyyy-MM")); } }
标签:
原文地址:http://blog.csdn.net/hgg923/article/details/42521171