This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Calendar class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar class" Watch "Calendar class" New topic

Calendar class

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
I have the following script:
Calendar c = Calendar.getInstance();
int a = c.get(Calendar.MONTH);
//GregorianCalendar cal = new GregorianCalendar();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-mm-dd");
This gives me the the following output
This gives the date and year right but every time i run the program the month always changes. It never gives me 2003-00-28 which it should as its 00 for January.
Can anyone tell me what I am missing?
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
mm is minutes. Use upper case MM for month. And it will not be 00 as this is a display date format. January will be 01.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
thanks, that worked.
Don't get me started about those stupid light bulbs.
subject: Calendar class
Similar Threads
Calendar() / Date() bug ???
Date range
TimeZone Date convertion
Date/Time conversion to GMT with DayLightSavings