转:
public static void main(String[] args) throws ParseException {
System.err.println(getDateArrByMonth("201909", "202002"));
}
public static List<String> getDateArrByMonth(String dateStart, String dateEnd) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
Date startDate = sdf.parse(dateStart);
Date endDate = sdf.parse(dateEnd);
Calendar c = Calendar.getInstance();
List<String> list = new ArrayList<String>();
SimpleDateFormat df = new SimpleDateFormat("yyyyMM");
for (; startDate.getTime() <= endDate.getTime(); ) {
String _startDate = df.format(startDate);
list.add(_startDate);
c.setTime(startDate);
c.add(Calendar.MONTH, 1); //加一个月
startDate = c.getTime();
}
return list;
}