Noda time makes working with timezones, well not a snap but better than dental surgery.
Convert a DateTime and TzDB Timezone to UTC
A TzDB timezone is one that looks like America/Edmonton
or, one might presume Mars/OlympusMons
1 | DateTimeZone timezone = DateTimeZoneProviders.Tzdb.GetZoneOrNull(timezoneId); |
Convert from a UTC to a zoned DateTime
1 | var local = new LocalDateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second); |
But be careful with this one because it might produce weird results around time change periods. If you want to avoid ambiguity or at least throw an exception for it consider InZoneStrictly