This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Murach's Java Programming and have Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Java Programming this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

calendar month problem  RSS feed

 
John Landon
Ranch Hand
Posts: 239
  • 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: 22265
38
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: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
Rob Spoor
Sheriff
Posts: 21019
84
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
Sheriff
Posts: 15985
86
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: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Thoughts on deprecation in Java
https://coderanch.com/t/683016/java/Deprecation-Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!