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

Calendar class

 
vidhya subramaniam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following script:
Calendar c = Calendar.getInstance();
int a = c.get(Calendar.MONTH);
System.out.println(a);
System.out.println(c.getTime());
//GregorianCalendar cal = new GregorianCalendar();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-mm-dd");
fmt.setCalendar(c);
System.out.println(fmt.format(c.getTime()));
c.roll(Calendar.DATE,false);
fmt.setCalendar(c);
System.out.println(fmt.format(c.getTime()));
This gives me the the following output
2003-22-29
2003-22-28
This gives the date and year right but every time i run the program the month always changes. It never gives me 2003-00-28 which it should as its 00 for January.
Can anyone tell me what I am missing?
Thanks,
Vidhya
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mm is minutes. Use upper case MM for month. And it will not be 00 as this is a display date format. January will be 01.
 
vidhya subramaniam
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that worked.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic