Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calendar fields  RSS feed

 
Paid O'Cuana
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try
rightNow.get(Calendar.YEAR)
You are printing the value of the YEAR constant not getting the year from the Calendar.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!