当我在日历中增加天数时,我遇到了一个奇怪的问题。我想循环一年中的每一天。这是我的代码
Date d = null;
SimpleDateFormat textFormat = new SimpleDateFormat("dd-MM-yyyy");
String paramDateAsString = "10-1-2012";
d = textFormat.parse(paramDateAsString);
Calendar cal = Calendar.getInstance();
cal.setTime(d);
for(int i = 0; i < 365; i++) {
cal.add(Calendar.DAY_OF_YEAR, 1);
System.out.println(cal.get(Calendar.YEAR)+"-"+cal.get(Calendar.MONTH)+1+"- "+cal.get(Calendar.DAY_OF_MONTH)+" 00:00:00'");
}
我得到这个输出:
...
2012-01-29 00:00:00'
2012-01-30 00:00:00'
2012-01-31 00:00:00'
2012-11-1 00:00:00'
2012-11 -2 00:00:00'
...