Touchstone developer Touchstone developer - 10 months ago 23
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) {


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");