aspose file tools
The moose likes Beginning Java and the fly likes calendar month problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "calendar month problem" Watch "calendar month problem" New topic
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
    
    2

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
    
    3

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calendar month problem
 
Similar Threads
Calendar() / Date() bug ???
GregorianCalendar object
log4j -best way to log to databse (or where is db.DBAppender if that's the best way)?
JAX-WS multiple implemetations of 1 endpoint interface
Patch in Java