• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calendar class

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, that worked.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic