Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

more Calendar stuff

 
andrew mcmillan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when outputting a date string from a Calendar in SHORT format i get the string '25.10.01'. but if i read this string back in to set the calendar date it assumes the year to be 0001 and not 2001.
how do i get the Calendar or DateForat class to assume that if year 01 is found assume its 2001 not 0001.
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andrew,
Whenever you use DateFormat you must use it on both ends. What does that mean? Well you have used it to output your string into SHORT form, so you must also use it when you read in back in from SHORT form. The following example shows what I am talking about.

Regards,
Manfred.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can also use a SimpleDateFormat, which allows you to specify how two-digit years are interpreted using the method set2DigitYearStart().
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic