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   }

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2022-02-19
  • 2022-12-23
猜你喜欢
  • 2021-11-29
  • 2021-11-24
  • 2022-12-23
  • 2021-10-19
  • 2021-09-28
  • 2022-12-23
  • 2021-05-05
相关资源
相似解决方案