Touchstone developer Touchstone developer - 2 years ago 82
Android Question

How to parse this type of date format?

I am parsing date of string type into Date format , but everytime got this exception

java.text.ParseException: Unparseable date: "2016-05-21T00:00:00" (at offset 4)

My code is :

String d = "2016-05-21T00:00:00";
DateFormat df = new SimpleDateFormat("yyyy MM dd HH:mm:ss", Locale.ENGLISH);
Date myDate = null;
try {
myDate = df.parse(d);
} catch (ParseException e) {

Answer Source

Your date string and DateFormat need to match. For your input "2016-05-21T00:00:00", the correct DateFormat is:

DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download