File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes MY month is shown 1 month ahead. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "MY month is shown 1 month ahead." Watch "MY month is shown 1 month ahead." New topic
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: MY month is shown 1 month ahead.