Alex Rivera | Logout

Human readable and parsable date format in Java

Asked 2009-09-23T20:49:09.830
20

I want to save a Date object to a readable string (for example 22/10/2009 21:13:14) that is also parsable back to a Date object.

I have tried many things and the best I could find was to use DateFormater for parsing and formating but it has a setback. When you format a date you lose seconds information. I tried to find if there is an option to format it and display the seconds (even better would be to the millisecond level since that's the resolution the Date object allows you to have) but I came up short.

Any ideas?

Edit
Report

2 Answers

5

SimpleDateFormat can format and parse a date based on a very simple pattern system that include second and even milliseconds.

answered 2009-09-23T20:52:40.493
2

A little off-topic, but I always feel the need to remind people that DateFormat and SimpleDateFormat are not thread safe! The Sun documentation clearly states this, but I keep finding code out in the wild where people stick a SimpleDateFormat in a static ...

answered 2009-09-24T09:19:06.680

Your Answer