I made a small program to count days. to count 150 days from May 22nd. But the result is 18th of October. The actual date is 19th October. Can anyone help me find whats wrong with my code.
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;
}
}