• Post Reply Bookmark Topic Watch Topic
  • New Topic

DateFormatting  RSS feed

 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a small question about fromating dates. I need to convert a date that I have as a String in the following format:
YYYY-MM-DD i.e "2004-01-12"
I need to convert this date into:
YYMMDD i.e 040112.
I was looking at SimpleDateFormat but can not see who to do this. Does anyone have any suggestions.
Thanks
Chris.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Note that SimpleDateFormat uses capitalization carefully (like most Java classes) - m has different meaning from M, y is different from Y, etc.
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
per the doc, y = year M = month and d = day
looking up into DateFormat, you'll find parse() and format()
parse parses a String into a Date, format formats a Date into a String
so:

should do it (if you try/catch the possible ParseException from format )
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, you saved me a few hours work.
Chris.
[ January 12, 2004: Message edited by: Chris Harris ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!