Why is the behaviour of datetime in JSON different on different systems (win xp, server 2003)?


My Web Application is split up in a WebGui and an WebService. The WebService is responsible for Business Logic and Database handling. From Javascript in the Browser I request data depending on a date and time that is an input from the Browser. This request gous to an .asmx Url in the WebGui and inside this function the webservice is called.

On my development system (windows xp) I get the right data, but when I install it on the test system I have to add the local time zone difference to get the right data.

For example I want the data for the date and time '21.07.2008 14:27:30' I have to send '21.07.2008 16:27:30'.

Why is the behaviour on the two systems different and what should I do to get on both systems the same behaviour?

  • Web GUI is in asp.net 2.0 c#
  • Web Service is in asp.net 1.1 c#


This is no Problem of interpreting the date in different formats as the date and time is sent in the JSON Protocol as "\/Date(1221738803000)\/". It is a problem of interpreting/forgetting the time zone.


Try using Json.NET to handle your serialization.

Note the comments here regarding serialization formats:


Depending on the culture settings of the server the date will be interpreted differently. I.e. given the date: 01.05.2008 a culture of en-GB (British) will read the date as First of May, a system with the culture en-US will read it as 5th of January.

To get around this you should ensure that dates are always transmitted in UTC format (yyyy-mm-dd) which will always be interpreted in that manner regardless of culture.

By : Wolfwyrd

I would suspect this has to do with the DateTime.Kind property introduced in .NET 2.0. By default this is set to DateTimeKind.Unspecified, which is most of the time handled the same as DateTimeKind.Local, so when the date is serialized it will be converted to UTC. You could try to set the Kind to DateTimeKind.Utc using DateTime.SpecifyKind(...) before passing it to the web service call.

By : csgero

This video can help you solving your question :)
By: admin