C# – How to figure out which timezone a (ASP.NET / MonoRail) website user is in

asp.netc++castle-monorailinternationalizationlocalization

So, I'm setting a cookie that should expire. However, I want this to work around the world. So I need to adjust my expiry date for the user's timezone.

So, I need to find out the user's timezone, server-side.

Is there a way to do this in the BCL? As in, something like relying on the CultureInfo.CurrentUICulture to be set correctly (which I believe the MonoRail LocalizationFilter does, but have not checked properly yet), and then figuring out which timezone the user is in (as well as accounting for daylight savings there too) based on that?

There's System.TimeZoneInfo in .NET 3.5, but little documentation on what the Ids are – whether they're ISO codes, or what.

Or am I going to rely on something on the client-side to push in this information from for example Date.getTimezoneOffset()? I'd prefer to avoid that, since, well, the client-side lies.

Best Solution

It's very simple. On the server, put a asp:hidden field and fill it with the current server's date/time. On the client, subtract the date/time in the hidden field from the current date on the client (new Date()) and you have your offset from GMT. Reverse for doing it on the server (e.g. new Date() in hidden field, subtract server time from hidden field value).