Search code examples
silverlighttimezonewcf-ria-servicessilverlight-5.0entity-framework-5

How can I manage timezone differences between client and server in Silverlight?


I have SL 5 app with a form which has a field for Date. I set the default date for this field in code like:

MyDate = System.DateTime.Today; 

Or

MyDate = System.DateTime.Now.Date; 

then submit the data with WCF Ria Service to save the data into database.

Problem is: if time zone on user client computer and Web server are different, the data of date would be saved with different value.

For example, today is Jan-03-2013, when I save the data from the form, in database, the data is saved as something like Jan-02-2013 23:00:00., not Jan-03-2013 00:00:00.

How to fix this problem?


Solution

  • you could try using

    MyDate = DateTime.UtcNow
    

    which would return utc time to the server then you can either store all datetimes as utc or manipulate it before saving to the the db (so it would be saved as server's local time)