Reputation: 8710
I have Strings representing dates with the format 2014-11-01T18:57:24.497Z
which I want to parse
as SimpleDateFormat
.
I am using the following code
// 2014-11-01T18:57:24.497Z
SimpleDateFormat startAnalyzing = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz");
Date start = startAnalyzing.parse(startDateAnalyzing);
When doing this I am getting an exception:
java.text.ParseException: Unparseable date: "2014-11-01T18:57:24.497Z"
at java.text.DateFormat.parse(DateFormat.java:357)
...
What I am doing wrong?
Upvotes: 1
Views: 63
Reputation: 16067
Firstly you are trying to parse a z
with Z
so either choose z
lower or upper for both (the String and the pattern).
Secondly, you need to "escape" the Z in the pattern (or z).
String startDateAnalyzing = "2014-11-01T18:57:24.497z";
SimpleDateFormat startAnalyzing = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'z'");
Output:
Sat Nov 01 18:57:24 CET 2014
Upvotes: 3