1

How can I parse JSON dates with GSON? Keeps getting errors.

The date format in the JSON looks like this:

/Date(1313613992133+0200)\

Any advice would be appreciated!

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
johan
  • 6,578
  • 6
  • 46
  • 68
  • Your date-string seams invalid (because of the `+`). Can you post a full JSON-example and tell where you get it from? – Lukas Knuth Aug 24 '11 at 11:01

2 Answers2

1

Try using

new Date(Long.parseLong("1313613992133")).toGMTString()
Siva Kumar
  • 893
  • 4
  • 14
  • 28
0

You can use:

    Date date = new Date(Integer.parseInt(jsonDateString.substr(6)));

Similar question answered here: How do I format a Microsoft JSON date?

Community
  • 1
  • 1
peter.bartos
  • 11,855
  • 3
  • 51
  • 62
  • Yes. That will probably work, but can I do this with the GSON parser? – johan Aug 24 '11 at 10:29
  • The String-method is called `substring()`, it differs from the JavaScript string. Also, the String can't be parsed since the `Integer.parseInt()`-method does not ignore the `)\` at the end. Also, in the string provided by the OP, there is a `+` which also causes the method to not work. – Lukas Knuth Aug 24 '11 at 10:54