views:

182

answers:

3

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.

+2  A: 

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.

James Curran
Maybe you could use the ToUniversalTime method on the DateTime class to do the conversion. http://msdn.microsoft.com/en-us/library/system.datetime.touniversaltime(VS.71).aspx
DaveB
That would work for the current time, but if they're saving a date in the future that date might have a different offset because of daylight savings time. I can't figure out how I would save that future date in utc time
Jon
A: 

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.

Simon Mark Smith
A: 

Can you not have javascript convert the date/time to UTC on the client?

P Daddy