Can anybody tell me why in the world I got this exception?
08-28 08:47:05.246: D/DateParser(4238): String received for parsing is 2013-08-05T12:13:49.000Z
private final static String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ"; public static Date parseDate(String stringToParse) { Date date = null; try { date = new SimpleDateFormat(DATE_FORMAT_PATTERN).parse(stringToParse); } catch (ParseException e) { Logger.logError(TAG, e); } return null; } 08-28 08:47:05.246: E/DateParser(4238): Exception: java.text.ParseException: Unparseable date: "2013-08-05T12:13:49.000Z" (at offset 23)
Advertisement
Answer
try using
String DATE_FORMAT_PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
The Z
at the end is usually the timezone offset. If you you don’t need it maybe you can drop it on both sides.