• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Formatting the date

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Everyone,

I have a string in this foramt :
Tue Dec 07 16:44:20 EST 2004
I want to convert it to a date of format :
mm.dd.yy
or
mm/dd/yy

I use following code, but it gives a ParseException.
DateFormat format = DateFormat.getDateInstance(DateFormat.SHORT);
format.setLenient(true);
Date date = format.parse(strDate);

Can anyone tell me what is wrong with above code ?

Thanks,
Gayatri
 
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How about something like:

 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should check the API docs for DateFormat and SimpleDateFormat to see the details about how these two classes work. In particular, the SimpleDateFormat docs have a table towards the top that explains what specifiers you can give in a valid format string.

Keep Coding!

Layne
reply
    Bookmark Topic Watch Topic
  • New Topic