locked
Problem with dates when getting a record from a WebService in Windows Azure RRS feed

  • Question

  • User-315082118 posted

    Hi,

    I’m using ASP.NET AJAX to call a WebService in the server from the client and get a record, the record contains dates, these dates are stored as their UTC values and when I get them to send them to the client are converted to the user’s local time using her time zone, this works great in Windows 7 and Windows Server 2008, but in Windows Azure I’m getting the value of the date minus 6 hours (the same offset of the user’s time zone).

    While debugging I can see that the date is obtained from SQL Azure correctly, and again it’s converted to the user’s local time correctly, it looks like the problem is generated when the record is serialized by ASP.NET AJAX into JSON to be send to the client, at this point it looks like it gets converted to the user’s browser local time, losing another 6 hours.

    ¿Has anybody seen something like this? ¿Is there a solution for this?

    thanks.

    Thursday, February 10, 2011 12:41 PM

Answers

  • User-315082118 posted

    Thanks for the response.

    After investigating further I noticed that what’s happening is that ASP.NET AJAX serializes dates differently depending on the operating system, Windows sends a JavaScript Date object, while Windows Azure sends the ticks of the date, since I store the UTC value of my dates in Windows I have to make the conversion to the user’s local time, while in Windows Azure this is not necessary it gets converted by JavaScript in the client, the solution then is to remove the UTC date conversion and then the dates work correctly in Windows Azure.

    This of course causes a problem when debugging since I get different results depending on the operating system, it would be nice for the Windows Azure people to standardize this in the emulator since we need reliable information while debugging.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 14, 2011 11:41 AM

All replies

  • User1509044783 posted

    Hello, Mr Mercury

    Can you please try using DateTimeOffset to eliminate the time difference.

    For your reference,

    http://msdn.microsoft.com/en-us/library/bb412170.aspx

    http://msdn.microsoft.com/en-us/library/system.datetimeoffset.aspx

    Sunday, February 13, 2011 9:31 PM
  • User-315082118 posted

    Thanks for the response.

    After investigating further I noticed that what’s happening is that ASP.NET AJAX serializes dates differently depending on the operating system, Windows sends a JavaScript Date object, while Windows Azure sends the ticks of the date, since I store the UTC value of my dates in Windows I have to make the conversion to the user’s local time, while in Windows Azure this is not necessary it gets converted by JavaScript in the client, the solution then is to remove the UTC date conversion and then the dates work correctly in Windows Azure.

    This of course causes a problem when debugging since I get different results depending on the operating system, it would be nice for the Windows Azure people to standardize this in the emulator since we need reliable information while debugging.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, February 14, 2011 11:41 AM