aspose file tools*
The moose likes Beginning Java and the fly likes java.util.Calendar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java.util.Calendar" Watch "java.util.Calendar" New topic
Author

java.util.Calendar

Amirtharaj Chinnaraj
Ranch Hand

Joined: Sep 28, 2006
Posts: 236
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

Joined: Feb 19, 2008
Posts: 2902
    
    1

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,



[LEARNING bLOG] | [Freelance Web Designer] | [and "Rohan" is part of my surname]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39865
    
  28
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

Joined: Sep 12, 2007
Posts: 300
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

Joined: Oct 13, 2005
Posts: 39865
    
  28
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

Joined: Sep 12, 2007
Posts: 300
Yeah!! Thanks.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39865
    
  28
You're welcome and I am sure you can spell "precede;" I obviously can't!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.util.Calendar