This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Calendar class - starts with month 0? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar class - starts with month 0?" Watch "Calendar class - starts with month 0?" New topic
Author

Calendar class - starts with month 0?

Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
I have a concern with the Calendar class, specifically with the MONTH field. Each month is assigned a value beginning with 0. This presents a problem when trying to display a date using a normal date format. Since JANUARY = 0, FEBRUARY = 1, etc. If I want the current date (which should give me "9/14/2004" using the following code:
I get "8/14/2004". I know I can just add 1 to the resulting month and I know counting in Java always starts at zero, but it seems like there should have been a better way so that every code that uses MONTH doesn't need to have " + 1" in it. Is there something that I'm not understanding and maybe a better way to do this?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
Dan Walin
Ranch Hand

Joined: Nov 11, 2003
Posts: 109
Thanks!
 
wood burning stoves
 
subject: Calendar class - starts with month 0?
 
Similar Threads
how to get the current date
Calendar returns wrong date?
Problem with java.util.Calendar.set(...)
Date Formatting Help
How to read a file