This code is always throwing a parse expection
java.text.ParseException: Unparseable date: "2011-10-28T17:06:03.046Z".
I'm using 1.6.0_24 java ver.
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ", Locale.US);
try {
utilDate = inFormat.parse("2011-10-28T17:06:03.046Z");
} catch (ParseException e) {
utilDate = null;
}
Can you point me to the error?
http://download.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html Says:
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" -> 2001-07-04T12:08:56.235-0700
So put Z
into '
and it should work or leave out the Z
completely:
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
try { utilDate = inFormat.parse("2011-10-28T17:06:03.046"); } catch (ParseException e) { utilDate = null; }
or
SimpleDateFormat inFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
try { utilDate = inFormat.parse("2011-10-28T17:06:03.046Z"); } catch (ParseException e) { utilDate = null; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.