I used java.util.Calendar like this: Calendar calendar = new GregorianCalendar(2001, 6, 30); calendar.add(Calendar.DATE, 1); //or calendar.add(Calendar.DATE, 1); //or calendar.add(Calendar.HOUR, 24); System.out.println("year: "+calendar.get(Calendar.YEAR)+ "\n month: "+calendar.get(Calendar.MONTH)+ "\n day: "+calendar.get(Calendar.DAY_OF_MONTH)+ "\n hour: "+calendar.get(Calendar.HOUR)+ "\n minute: "+calendar.get(Calendar.MINUTE)+ "\n sencond: "+calendar.get(Calendar.SECOND) ); the result is always 2001-6-31! then i use java.util.Date: Date date = new Date(2001, 6, 30); long current = date.getTime(); current += 24 * 3600 * 1000; //add one day System.out.println(.. and the result is the same! who answer me?
rani bedi
Ranch Hand
Joined: Feb 06, 2001
Posts: 358
posted
0
There is no problem with the java.util.date object. If you try to convert the time back into the date object you would see that it prints the next date.
Date date = new Date(2001, 6, 30); long current = date.getTime(); current += 24 * 3600 * 1000; //add one day Date newDate = new Date(current); System.out.println(" date " + date); System.out.println(" newDate " + newDate);
Cheers,<br />Rani<br />SCJP, SCWCD, SCBCD
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
If you are referring to 6-31 and thinking it is June 31 you are mistaken. Java months start at 0 for Jan. So 6-31 is Jul 31.