1

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?

Guruprasad J Rao
  • 29,410
  • 14
  • 101
  • 200

1 Answers1

5

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

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
assylias
  • 321,522
  • 82
  • 660
  • 783