views:

428

answers:

4

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#

Update

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.

A: 

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.

Wolfwyrd
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.(I have updated the question)
Roland Bär
A: 

If the timezone doesn't matter, instead pass the date/time as a formatted string, this way you know exactly how it will look, and use DateTime.Parse to turn it into a DateTime on the server side.

Robert C. Barth
+1  A: 

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.

csgero
+1  A: 

Try using Json.NET to handle your serialization.

Note the comments here regarding serialization formats:

http://james.newtonking.com/archive/2008/08/25/json-net-3-0-released.aspx

nelsonmichael