Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

DateTimeExtensions - C#

RSS
Modified on Thu, Dec 28, 2017, 6:26 PM by Administrator Categorized as ·Net Framework
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.