我做了一个小程序来计算天数。从 5 月 22 日算起 150 天。但结果是 10 月 18 日。实际日期是 10 月 19 日。谁能帮我找出我的代码有什么问题。
Calendar mine = new GregorianCalendar(2013, Calendar.MAY,22);
int month = Calendar.MAY;
int counter = 0;
for(int i=mine.get(Calendar.DAY_OF_MONTH);i<=mine.getActualMaximum(Calendar.DAY_OF_MONTH);i++){
System.out.println("i "+i);
counter++;
System.out.println("counter "+counter);
if(i==mine.getActualMaximum(Calendar.DAY_OF_MONTH)){
month++;
i=1;
mine.set(2013, month, i);
counter++;
System.out.println("i "+i+" "+mine.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH));
if(counter == 150){
System.out.println("day "+i+ counter +"days"+ "month:"+ mine.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH));
break;
}
}
if(counter == 150){
System.out.println("i "+i+" counter "+ counter +" date:"+mine.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.ENGLISH));
break;
}
}