| Author |
calendar month problem
|
John Landon
Ranch Hand
Joined: Sep 25, 2008
Posts: 221
|
|
Run this code right now: what I get is: Tue Oct 28 14:48:45 EDT 2008 9 why 9??? it knows it's Oct. Should be 10~!!! And by the way, is there a way for it to return me values with 0 in front if it's single digit? Thanks. [ October 28, 2008: Message edited by: John Landon ] [ October 28, 2008: Message edited by: John Landon ]
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
The designers of Java decided it would be preferable for the months to be numbered starting at zero. (Once you've drunk enough Java kool-aid that sounds perfectly normal.) As for formatting of dates and times, if you have specific requirements you should use a SimpleDateFormat object. You can display dates in just about any way you like then.
|
 |
John Landon
Ranch Hand
Joined: Sep 25, 2008
Posts: 221
|
|
|
thanks
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Originally posted by Paul Clapham: The designers of Java decided it would be preferable for the months to be numbered starting at zero. (Once you've drunk enough Java kool-aid that sounds perfectly normal.)
The very same designers who then let weekdays start at one (Sunday).
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Jesper de Jong
Java Cowboy
Bartender
Joined: Aug 16, 2005
Posts: 12929
|
|
|
Note that class Calendar has a set of constants: Calendar.JANUARY, Calendar.FEBRUARY etc. which correspond to the month numbers that Calendar uses (0 to 11). You should use those constants when dealing with class Calendar instead of literal month numbers.
|
Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
|
 |
John Landon
Ranch Hand
Joined: Sep 25, 2008
Posts: 221
|
|
|
thanks guys
|
 |
 |
|
|
subject: calendar month problem
|
|
|