Author
MY month is shown 1 month ahead.
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
I feed a year, a month and a date into the int variables yy,mm,dd respectively and then call the code below. for example if I assign 2001 to yy and 1 to mm and 1 to dd the date it shows its Feb 1, 2001. Why is this happening? calendar.set(yy,mm,dd); java.util.Date date=calendar.getTime() System.out.println(date); <- showing date 1 month ahead
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 368
posted Apr 29, 2007 11:59:00
0
You need to give the month as 0 if you want January.For e.g. public static void main(String [] args) { Calendar c = Calendar.getInstance(); c.set(2001,0,1); java.util.Date date=c.getTime(); System.out.println(date); } O/P-> Mon Jan 01 03:12:44 GMT+05:30 2001
Thanks and Regards
Tontang Bei
Ranch Hand
Joined: Oct 21, 2006
Posts: 130
Thank you guys. I got very frustrated about this.
subject: MY month is shown 1 month ahead.