Amal Madawa Amal Madawa - 1 year ago 151
Java Question

how to Parse String Date to MongoDB date type

i'm have string dates like

Wed Aug 17 17:22:51 IST 2016
to parse to ISOdate. so I have tried following code to do that.

String tdate = "Wed Aug 17 17:22:51 IST 2016";
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
Date pubDate = sdf.parse(tdate);

but it gave me:

java.text.ParseException: Unparseable date: "Wed Aug 17 17:22:51 IST 2016"

Answer Source

try parsing with

SimpleDateFormat sdf = new SimpleDateFormat("E MMM dd HH:mm:ss Z yyyy");

hope it helped

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download