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)
Try this: SimpleDateFormat in = new SimpleDateFormat("EEE MMM dd HH:mm:ss Z yyyy"); in. setTimeZone(TimeZone. getTimeZone("Asia/Calcutta")); //or Asia/Jerusalem String s2 = "Fri Oct 23 11:07:08 IST 2015"; Date date = in.
DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat , allows for formatting (i.e., date -> text), parsing (text -> date), and normalization.
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.
Use X
instead of Z
at the end of the format string:
yyyy-MM-dd'T'HH:mm:ss.SSSX
to parse ISO-8601 format timezone offsets.
(Only works if you use Java 7. See this question).
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