Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to parse date to EEE MMM dd HH:mm:ss zzz yyyy format?

Tags:

java

date

parsing

I am getting date from database as 2013-05-03 00:20:29.0. I want to parse the date to EEE MMM dd HH:mm:ss zzz yyyy format, but when I am parsing it, I am getting this exception:

java.text.ParseException: Unparseable date: "2013-05-03 00:20:29.0"

My code is below:

    String createdDate = "2013-05-03 00:20:29.0";
    SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
    Date parseDate = format.parse(createdDate);
like image 929
developer Avatar asked Nov 20 '25 17:11

developer


1 Answers

You have to adjust the Format pattern. Format must be yyyy-MM-dd HH:mm:ss.S

Try this

SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S");

See http://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

like image 190
cinhtau Avatar answered Nov 23 '25 07:11

cinhtau



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!