Last active
January 24, 2024 22:23
-
-
Save justinsaraceno/c89923ab2374b41c7069 to your computer and use it in GitHub Desktop.
Convert UTC DateTime to a specified time zone using Noda Time
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// the time zone to convert to | |
var timeZone = DateTimeZoneProviders.Tzdb["US/Eastern"]; | |
// the date as UTC - this could be from a data store | |
var fakeUtcDate = new DateTime(2015, 11, 01, 07, 30, 00); | |
// convert to instant from UTC - see http://stackoverflow.com/questions/20807799/using-nodatime-how-to-convert-an-instant-to-the-corresponding-systems-zoneddat | |
var instant = Instant.FromDateTimeUtc(DateTime.SpecifyKind(fakeUtcDate, DateTimeKind.Utc)); | |
var result = instant.InZone(timeZone).ToDateTimeUnspecified(); |
Thank you Justin
Thanks! Nice snippet!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you. This answers my search..