How to parse this format date string 2013-03-13T20:59:31+0000 to Date object?
I'm trying on this way but it doesn't work.
DateFormat df = new SimpleDateFormat("YYYY-MM-DDThh:mm:ssTZD"); Date result = df.parse(time);
I get this exception from the first line:
java.lang.IllegalArgumentException: Illegal pattern character 'T'
parse() The Date. parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31). Only the ISO 8601 format ( YYYY-MM-DDTHH:mm:ss.
SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy", Locale. ENGLISH); String dateInString = "7-Jun-2013"; Date date = formatter. parse(dateInString); In the above example, we first need to construct a SimpleDateFormat object by passing the pattern describing the date and time format.
Dates are formatted using the following format: "yyyy-MM-dd'T'hh:mm:ss'Z'" if in UTC or "yyyy-MM-dd'T'hh:mm:ss[+|-]hh:mm" otherwise. On the contrary to the time zone, by default the number of milliseconds is not displayed. However, when displayed, the format is: "yyyy-MM-dd'T'hh:mm:ss.
Try:
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
check http://developer.android.com/reference/java/text/SimpleDateFormat.html
in specific:
yyyy-MM-dd 1969-12-31 yyyy-MM-dd 1970-01-01 yyyy-MM-dd HH:mm 1969-12-31 16:00 yyyy-MM-dd HH:mm 1970-01-01 00:00 yyyy-MM-dd HH:mmZ 1969-12-31 16:00-0800 yyyy-MM-dd HH:mmZ 1970-01-01 00:00+0000 yyyy-MM-dd HH:mm:ss.SSSZ 1969-12-31 16:00:00.000-0800 yyyy-MM-dd HH:mm:ss.SSSZ 1970-01-01 00:00:00.000+0000 yyyy-MM-dd'T'HH:mm:ss.SSSZ 1969-12-31T16:00:00.000-0800 yyyy-MM-dd'T'HH:mm:ss.SSSZ 1970-01-01T00:00:00.000+0000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With