Unparseable date issue with java time offset

513 views Asked by At

So I am receiving date in 2017-01-01T01:34:00+00:00 format from server and I have below SimpleDateFormatter picked up after seeing many examples.

SimpleDateFormat serverToClientFormat=
                 new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'",Locale.getDefault());

But when I try to parse it with below lines

serverToClientFormat.parse(object.getString("date"))

the string received from server to date format, it throws

java.text.ParseException: Unparseable date: "2017-01-01T01:34:00+00:00"

What probably could I try else to parse above format?

1

There are 1 answers

6
assylias On BEST ANSWER

You are using the literal Z instead of the Z pattern letter - so your format expects the letter Z in the input, not a time zone offset.

Also, the Z pattern doesn't accept the : in the offset. Try with X instead (without the single quotes) and it should work fine:

new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");

Live Example