开发者

ASP.NET: Problems using Timezone in Profile to convert from UTC

Users have their timezones stored in ASP.NET profiles as strings. I want to use those timezones to convert from UTC for a given user:

Dim timezoneFromProfile = HttpContext.Profile("TZ").ToString
Dim timezone = TimeZoneInfo.FromSeri开发者_运维百科alizedString(timeZoneFromProfile) ' FAIL
Dim convertedTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timezone)

The problem is that TimeZoneInfo.FromSerializedString() expects its input to not be just a string such as:

(UTC-08:00) Pacific Time (US & Canada)

I can serialize the user's TimeZoneInfo into the ASP.NET Profile perhaps using XML, but I'm led to believe that using anything other than simple types such as Strings and Integers results in poor performance with respect to Profiles.

What's the best way forward?


You can load a timezone from its "Id":

TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");

GetSystemTimeZones will give you the list of Ids. Note: these are framework 3.5 methods.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜