I would appreciate any help with finding bug for this exception:
java.text.ParseException: Unparseable date: "2007-09-25T15:40:51.0000000Z"
and following code:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"); Date date = sdf.parse(timeValue); long mills = date.getTime(); this.point.time = String.valueOf(mills);
It throws expcetion with Date date = sdf.parse(timeValue);
.
timeValue = "2007-09-25T15:40:51.0000000Z";
, as in exception.
Thanks.
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.
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.
parseexception: unparseable date” error message, when you try to parse the date string into another desired format. Don't worry it's a very common error message that users generally faced while parsing a date in java using SimpleDateFormat class.
Z
represents the timezone character. It needs to be quoted:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
In Java 7 you can also use the X
pattern to match an ISO8601 timezone, which includes the special Z
(UTC) value:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSSSX"); Date date = sdf.parse("2007-09-25T15:40:51.0000000Z");
However, it seems to require an exact number of millisecond characters in the pattern, which is not required for the 'Z' character pattern, and is rather inconvenient. I think this is because the ISO8601 definition also includes "two-digit hours", which are just numbers, so cannot be distinguished by the parser from the preceding milliseconds.
So this version would be fine for timestamps down to second precision, less so for milliseconds.
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