实现思路:
通过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));
时间: 2024-10-09 08:45:02