Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to Date Object in Java

Tags:

java

date

I need to parse the following string into a date object in java:

String time = "Jul 24 2012 05:19:34";
DateFormat df = new SimpleDateFormat("MM dd yyyy HH:mm:ss");
Date date = df.parse(time);

The code throws this exception:

Unparseable date: "Jul 24 2012 05:19:34"

Does anyone know how to fix this?

like image 252
user1467855 Avatar asked Aug 09 '26 19:08

user1467855


1 Answers

Make it

DateFormat df = new SimpleDateFormat("MMM dd yyyy HH:mm:ss");

Note: MMM

like image 65
jmj Avatar answered Aug 12 '26 10:08

jmj



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!