File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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: 38519
    
  23
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: 38519
    
  23
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: 38519
    
  23
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