Save user time zone preferences

My requirement here is pretty standard; I need to allow users to select their current TimeZone and save it against their account. Then I use this value to convert the stored values DateTimeto localized time.

My current thinking is that I will allow users to select .NET TimeZoneInfo.Idfrom the list (stored in the database for a more convenient description, but built with TimeZoneInfo.GetSystemTimeZones()). Then I use this value to return the appropriate TimeZoneInfoinstance using TimeZoneInfo.FindSystemTimeZoneById()and perform the conversion. The main problem that I see here is that it TimeZoneInfo.Idis a value stored in the registry and is not a "standard" identifier (compared to Olson, for example). Thus, it is possible that server updates / migrations can completely invalidate stored identifiers and break down conversions.

In short - is this approach valid / safe? If not, is there a better way to store user time zone preferences, as well as daylight saving time processing, etc. Without a ton of additional logic?

+5
source share
1 answer

I just found this old question unanswered, so I thought I should strike him.

In short - is this approach valid / safe?

It all depends on what you plan to do with them.

If you just use it in server code, then yes. You just save the Idtime zone and show the user the appropriate one DisplayName. FindSystemTimeZoneByIdand are GetSystemTimeZonesquite applicable for this.

, , Id - DisplayName Windows, . , .Net DisplayName.

Microsoft Windows Windows Update. , tzres.dll. , TimeZoneInfo .

, Id - . Windows. , , , , "GMT" , "UTC". Id , , . , Windows, . - .

Windows:

  • DST . , 2010 . Microsoft , , . , , .

  • Windows XP/2003 Vista/2008. , , .

  • Microsoft . IANA/Olson. . wiki.

, TimeZoneInfo DateTime DateTimeOffset. . DateTimeOffset , DateTime . :

.Net NodaTime. , CLDR . API, . , , , LocalDateTime, ZonedDateTime, OffsetDateTime Instant.

, , . TZDB / . tz .

, NodaTime, TZDB, , . () , IANA - , .

+8

All Articles