Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java calander class

 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the Java Calender class and I am reading in a Year for a Day of Year, for example 2001 for the year, and 045 for the Day of Year. Does anyone know how I would could get this Day of Year to set the month as Feburary. Is there anything in the Calander class which can read the Day of Year and automatically tell what month it is? If there is how would I do this?
 
shilpa kulkarni
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This piece of code returns date as 14 Feb 2001.
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2001);
cal.set(Calendar.DAY_OF_YEAR, 45);
System.out.println(cal.get(Calendar.DATE));
System.out.println(cal.get(Calendar.MONTH)+1);
System.out.println(cal.get(Calendar.YEAR));
 
Chanpreet Julka
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks.. ill check it out
 
Matthew Phillips
Ranch Hand
Posts: 2676
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This post will probably be more appropriate in the Java in general intermidiate forum. I will move it there.
Matthew Phillips
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic