wood burning stoves 2.0*
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calendar fields" Watch "Calendar fields" New topic

Calendar fields

Paid O'Cuana

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
and the did the System.out and it still said 1.
If I print out the string version of the Calendar instance
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
You are printing the value of the YEAR constant not getting the year from the Calendar.
Consider Paul's rocket mass heater.
subject: Calendar fields