This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Calendar fields Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar fields" Watch "Calendar fields" New topic
Author

Calendar fields

Paid O'Cuana
Greenhorn

Joined: Mar 05, 2003
Posts: 24
I'm having trouble with the Calendar class.
I create my Calendar like so:
Calendar rightNow = new GregorianCalendar();
When I check what year it is
System.out.println("The year is "+rightNow.YEAR);
it prints out '1' for some reason
I even tried
rightNow.set(rightNow.YEAR,2003);
and the did the System.out and it still said 1.
If I print out the string version of the Calendar instance
System.out.println(rightNow.toString());
it shows the YEAR field as 2003, but any operation I use YEAR in has YEAR set to 1.
Any idea what stupid mistake I'm making?
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Try
rightNow.get(Calendar.YEAR)
You are printing the value of the YEAR constant not getting the year from the Calendar.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar fields
 
Similar Threads
help me on this.. :-)
Tough Calendar class questions
Festivals and economy
Calendar class YEAR and DAY_OF_YEAR
Assistance with JApplet