Convert client time to utc time to save into sql
How could I go about having a client in various time zones select a date and time in their web browser and save it as utc time in my sql database? This date is a date in the future, so whether or not the date is in daylight savings time could cha开发者_如何转开发nge so I'll need to account for that.
The site is a asp.net c# site.
Have a hidden field in your HTML, and have it filled with the current time via javascript. Since it's been done by the user's browser, it will be in their local time. On the server side, compare that to the server's local time for find the time zone offset.
The way we ended up going about this was to add storage of a clients timezone as part of their user configuration. That way we know exactly where they are and you can use the built in conversion features of Framework 3.5 to perform all conversions between Local and UTC (this takes into account daylight savings)
See here http://msdn.microsoft.com/en-us/library/bb382770.aspx
I am assuming that you have authenticated users, but then if you are storing user selected dates in your database it's a fair bet.
Can you not have javascript convert the date/time to UTC on the client?
精彩评论