Javascript Json Deserialization

Posted on  by

I have an javascript object with Date property which is being converted to JSON using JSON.stringify I am on GMT+4 time zone (Russia/Moscow) For example, 5 Jan 2012 converts to 2012-01-04T20:00:00.000Z 5 Jan 1975 converts to 1975-01-04T20:00:00.000Z But in 1975 it was GMT+3 time zone, as daylight saving was canceled in Russia in 2011. So when it cames to server (java) it deserializes as: 2012-01-04T20:00:00.000Z becames 5 Jan 2012 00:00 - OK 1975-01-04T20:00:00. Games In The Dark Ep on this page. 000Z becames 4 Jan 1975 23:00 - WRONG!

What is the recommended way to convert Date object to JSON in Javascript? I prefer to stick to javascripts ISO 8601 date format, when parsing it correctly it'll will automatically handle timezone differences. In java you can parse a javascript Stringified JSON date as follows: String iso8601Date = '2013-08-13T14:15:00.000Z'; SimpleDateFormat formatter = new SimpleDateFormat('yyyy-MM-dd'T'HH:mm:ss.SSSXXX'); Date parsedDate = formatter.parse(iso8601Date); When turning it back into strings, you'll have something like this //'2013-08-13T16:15:00.000+02:00' String formattedDate = formatter. Torrent Doctor Who Season 1 Episode 2. format(parsedDate); For parsing JSON I use FlexJson, which you can configure like this.

See More On Stackoverflow