wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes calendar month problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calendar month problem" Watch "calendar month problem" New topic
Author

calendar month problem

John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
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: 18907
    
    8

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: 227
thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19761
    
  20

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 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14350
    
  22

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 8 API documentation
John Landon
Ranch Hand

Joined: Sep 25, 2008
Posts: 227
thanks guys
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: calendar month problem