File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calendar class YEAR and DAY_OF_YEAR

 
Herbert Kornfeld
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I want is to just print out the current year and the day of the year - I am using this code:
Calendar calendar = Calendar.getInstance();
String year = Integer.toString(calendar.YEAR);
System.out.println("year is :" + calendar.YEAR);
System.out.println("year is :" + year);
String dayno = Integer.toString(calendar.DAY_OF_YEAR);
which is conistently printing out a 1 for the year and a 6 for the day of year - no matter when you run the program.
I am sure I am just missing something obvious but I can't figure out what it is.
Many Thanks - Happy Holidays!
 
fei long
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Herbert,
the 'YEAR' or 'DAY_OF_YEAR' is used for 'get' and 'set' methods only according to API. So try following:
int year = calendar.get(calendar.YEAR);
int dayno = calendar.get(calendar.DAY_OF_YEAR);
Hope this can help you.
 
Herbert Kornfeld
Ranch Hand
Posts: 32
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great - thanks a lot!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic