实现思路:

  通过Calendar类的before来判断两个日期是否符合前一个日期小于后一个日期。

  实现:

 1         Calendar c1 = Calendar.getInstance();
 2         Calendar c2 = Calendar.getInstance();
 3         c1.set(2014, 9, 30);
 4         c2.setTime(new Date());
 5         System.out.println(c1.get(Calendar.YEAR)+" "+c1.get(Calendar.MONTH));
 6         while (c1.before(c2)) {
 7             int m = c1.get(Calendar.MONTH)+1;
 8             System.out.println(c1.get(Calendar.YEAR)+" "+(c1.get(Calendar.MONTH)+1));
 9             c1.add(Calendar.MONTH,1);
10         }
11         System.out.println(c1.get(Calendar.YEAR)+" "+(c1.get(Calendar.MONTH)+1));

 

相关文章:

  • 2021-10-19
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-04-25
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
  • 2021-10-18
相关资源
相似解决方案