You need to quote the T
because you want it to match literally. You also want X
as the format specifier for the time zone, not Z
:
yyyy-MM-dd'T'HH:mm:ss.SSSSSSX
Or you could specify the time zone as UTC, and quote the Z as well.
yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'
However, you may still have problems because that's going to interpret 213757 as a number of milliseconds, not microseconds.
I'm not sure there's a clean way of parsing microseconds with SimpleDateFormat
- you're probably best off just parsing a substring:
String text = "2014-04-24T08:51:58.213567Z";
// You could just hard code the length, but this feels easier to read
String trimmed = text.substring(0, "yyyy-MM-ddTHH:mm:ss.SSS".length());
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
format.setTimeZone(TimeZone.getTimeZone("Etc/UTC");
Date date = format.parse(trimmed);
Note that you definitely want Etc/UTC
as the time zone, because the input is in UTC... that's what the 'Z' means at the end of the string.