Reputation: 51
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 change so I'll need to account for that.
The site is a asp.net c# site.
Upvotes: 2
Views: 1200
Reputation: 29537
Can you not have javascript convert the date/time to UTC on the client?
Upvotes: 0
Reputation: 1170
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.
Upvotes: 1
Reputation: 103535
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.
Upvotes: 2