Parsing ISO 8601 date format like 2015-06-27T13:16:37.363Z in Java [duplicate]

Try with this pattern (note the X at the end and the ‘T’ in the middle):

"yyyy-MM-dd'T'HH:mm:ss.SSSX"

From Java’s SimpleDateFormat’s documentation:

ISO 8601 Time zone:

For parsing, “Z” is parsed as the UTC time zone designator.

And, from the part where it describes the different characters:

X – Time zone – ISO 8601 time zone

EDIT

If using Android, then “X” is not supported.

You can use this pattern (note Z is a literal now):

"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"

But then you’ll get the date on your current timezone and would need to convert it to UTC if needed.

Leave a Comment