Skip to content

How to get correct date time by TimeZoneInfo when time zone offset is changed in history #112265

Closed Answered by elgonzo
Li7ye asked this question in Q&A
Discussion options

You must be logged in to vote

If you need something now that works on Windows (and other platforms targetted by .NET), try using the NodaTime package which supports IANA TZDB (time zone database).

Your code example adopted for NodaTime could for example look like this:

var instantTime = Instant.FromUtc(1942, 5, 1, 0, 0);
var zone = DateTimeZoneProviders.Tzdb.GetZoneOrNull("Asia/Singapore");
var zonedTime = instantTime.InZone(zone);

Console.WriteLine(zonedTime);

with the output of this example being something like 1942-05-01T09:00:00 Asia/Singapore (+09).

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@Li7ye
Comment options

@elgonzo
Comment options

Answer selected by Li7ye
@Clockwork-Muse
Comment options

@Li7ye
Comment options

@Clockwork-Muse
Comment options

@Li7ye
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants