views:

207

answers:

2

Hello,

In database I store all date/times in UTC.

I know user's timezone name ("US Eastern Standard Time" for example).

In order to display correct time I was thinking that I need to add user's timezone offset to UTC date/time. But how would I get timezone offset by timezone name?

Thank You!

+3  A: 

You can use the TimeZoneInfo class's GetSystemTimeZones() method to fetch the list of all timezones configured on your server and match it to the one from your client.

Though why do you have timezones in the format "US Eastern Standard Time"? Where did that come from?

Dean Harding
Great idea, will try it now :)I'm populating one drop down with collection returned by GetSystemTimeZones()
Daniil Harik
+2  A: 

You can use TimeZoneInfo.FindSystemTimeZoneById to get the TimeZoneInfo object using the supplied Id, then TimeZoneInfo.GetUtcOffset from that:

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("US Eastern Standard Time");
TimeSpan offset = tzi.GetUtcOffset( myDateTime);
Oded
This solved my problem. Thank You!
Daniil Harik