• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.util.Calendar

 
Amirtharaj Chinnaraj
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys
i have written a small program as shown below



when i run the sample i got the output as below



my questions is why cal.month in line 2 is printing 2 and MONTH=11 is printed for line 1
[edit]Insert new lines to fit display onto the screen. CR[/edit]
[ December 03, 2008: Message edited by: Campbell Ritchie ]
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See docs,

Calendar is an abstract class and field MONTH is constant field, used to set and get the month field from Calendar instance !!

like,

 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if you go through the Calendar class and look for the DECEMBER field and click "constant field values" you will find why it doesn't print 12.
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

If you go through the Calendar API you will find following line -



I don't think this is for the purpose you want to achieve. This field is for internal purpose of API.
If you want to get the month as returned by your first line, you have to write -

Cheers,
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Patricia Samuel:
. . .. . .


Spelt "cal.get(Calendar.MONTH)" please. Remember Java is case-sensitive, and you should recede a static member by the name of its class.
 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah!! Thanks.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome and I am sure you can spell "precede;" I obviously can't!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic