Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

MY month is shown 1 month ahead.

 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 368
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Tontang Bei
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys. I got very frustrated about this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic