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,031
  • 13
  • 99
  • 190

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
  • 959,406
  • 173
  • 1,780
  • 1,769
assylias
  • 310,138
  • 72
  • 642
  • 762