public static class DateTimeExtensions { /// <summary> /// Returns a DateTimeOffset object of a specified date in a specified time zone /// </summary> /// <param name="dt">The date</param> /// <param name="timeZoneName">The name of the time zone. MUST be one of the /// [Id] values from the TimeZoneInfo.GetSystemTimeZones() method call.</param> /// <returns></returns> public static DateTimeOffset SpecifyTimeZone(this DateTime dt, string timeZoneName) { var tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName); return new DateTimeOffset(dt, tzi.GetUtcOffset(dt)); } }
ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.