• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calendar month problem

 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15482
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
John Landon
Ranch Hand
Posts: 228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic