Touchstone developer Touchstone developer - 1 year ago 91
Android Question

Parse a date-time string in ISO 8601 format without offset-from-UTC

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