1 private static List<String> getMonthBetween(String minDate, String maxDate) throws ParseException { 2 ArrayList<String> result = new ArrayList<String>(); 3 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");//格式化为年月 4 5 Calendar min = Calendar.getInstance(); 6 Calendar max = Calendar.getInstance(); 7 8 min.setTime(sdf.parse(minDate)); 9 min.set(min.get(Calendar.YEAR), min.get(Calendar.MONTH), 1); 10 11 max.setTime(sdf.parse(maxDate)); 12 max.set(max.get(Calendar.YEAR), max.get(Calendar.MONTH), 2); 13 14 Calendar curr = min; 15 while (curr.before(max)) { 16 result.add(sdf.format(curr.getTime())); 17 curr.add(Calendar.MONTH, 1); 18 } 19 20 return result; 21 }