| Author |
Problem with GregorianCalendar
|
Gaurav Mac Mathur
Ranch Hand
Joined: Feb 19, 2002
Posts: 47
|
|
Hi The requirement is to roll ahead one day and then roll back to same day. if i use rolll function, only date is rolled and not Month If i use add function,I am not able to roll back the year using the add(-1). GregorianCalendar c= new GregorianCalendar(2003,12,31); System.out.println(" Date on 31 Dec 2003 -->"+ c); c.add(Calendar.DATE,+1); System.out.println(" Date after 31 Dec 2003 -->"+ c); c.add(Calendar.DATE,-1); System.out.println(" Date on Day before the days after 31 Dec 2003 -->"+ c); Am i missing something ??? Regards Gaurav :roll: :roll: :roll: :roll: :roll:
|
 |
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
|
|
Yes--months are 0 indexed! When you say: new GregorianCalendar(2003,12,31); you are specifying the 31st day of the thirteenth month of 2003--Which is Jan 31, 2004. Change to new GregorianCalendar(2003,11,31); to get the desired result. (Or use new GregorianCalendar(2003, Claendar.DECEMBER, 31)) (And use SimpleDateFormats to more easily display the dates; that's how I spotted the problem: [ July 08, 2003: Message edited by: Joel McNary ]
|
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
|
 |
Gaurav Mac Mathur
Ranch Hand
Joined: Feb 19, 2002
Posts: 47
|
|
Yes I stand corrected... DEC is 11th month of Year in Java Thanks
|
 |
 |
|
|
subject: Problem with GregorianCalendar
|
|
|