Java Date Format – How to Format Dates in Java

datedate-formatformatjava

Have String str "May 23 2011 12:20:00", want to convert it to date such this:

Date date = (new SimpleDateFormat("MMM dd yyyy HH:mm:ss")).parse(str);

It always gives me ParseException Unparsable date format: 'May 23 2011 12:20:00'.

Looked for similar issues, seems everything right.

What is wrong?

Best Answer

You may need to additionally specify the Locale, when the default Locale of your VM is not an English one:

Date date = (new SimpleDateFormat("MMM dd yyyy HH:mm:ss", Locale.US)).parse(str);
Related Question