I need to convert a timestamp string to java.util.Date
. E.g.:
MMDDYYHHMMSS
to MM-DD-YY HH-MM-SS
Where MM
You can do it like this:
DateFormat format = new SimpleDateFormat("MMddyyHHmmss");
Date date = format.parse("022310141505");
but I would strongly recommend that you use Joda Time instead. It's a better date/time library by a long, long way. In particular, the formatters/parsers in Joda Time are thread-safe, so you can reuse them freely and statically; java.text.SimpleDateFormat
isn't thread-safe, so you either need to create one per thread or serialize access to it with a synchronized
block.