List<String> ms = DateUtils.getMonths(7,"yyyyMM"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); for (String s : ms) { Calendar ca = Calendar.getInstance(); try { ca.setTime(sdf.parse(s + "01")); } catch (ParseException e) { e.printStackTrace(); } ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); String last = sdf.format(ca.getTime()); System.out.println("===============last:"+last); } Calendar ca = Calendar.getInstance(); ca.setTime(new Date()); ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH)); String last = sdf.format(ca.getTime()); System.out.println("===============当前月最后一个月:"+last);
时间: 2024-11-08 23:02:23