aspose file tools*
The moose likes Beginning Java and the fly likes Calendar class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Calendar class" Watch "Calendar class" New topic
Author

Calendar class

vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
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

Joined: May 05, 2000
Posts: 13974
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.


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
vidhya subramaniam
Ranch Hand

Joined: Jul 14, 2001
Posts: 91
thanks, that worked.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calendar class
 
Similar Threads
!SimpleDateFormat
Date/Time conversion to GMT with DayLightSavings
Date range
Calendar() / Date() bug ???
TimeZone Date convertion