DateTime - ConvertTimeBySystemTimeZoneId

Converts a time to the time in another time zone based on a time zone identifier.

Try it

public static void Main()
{
    DateTime date = DateTime.Now;

    // C# Extension Method: DateTime  - ConvertTimeBySystemTimeZoneId
    DateTime result = date.ConvertTimeBySystemTimeZoneId("Tokyo Standard Time");
	
	Console.WriteLine("Current Time in different time zones:\n");

    Console.WriteLine("{0}: {1}",TimeZoneInfo.Local.StandardName, date);
	Console.WriteLine("{0}: {1}","Tokyo Standard Time", result);
}

View Source
using System;

public static partial class Extensions
{
    /// <summary>
    ///     Converts a time to the time in another time zone based on the time zone&#39;s identifier.
    /// </summary>
    /// <param name="dateTime">The date and time to convert.</param>
    /// <param name="destinationTimeZoneId">The identifier of the destination time zone.</param>
    /// <returns>The date and time in the destination time zone.</returns>
    public static DateTime ConvertTimeBySystemTimeZoneId(this DateTime dateTime, String destinationTimeZoneId)
    {
        return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, destinationTimeZoneId);
    }

    /// <summary>
    ///     Converts a time from one time zone to another based on time zone identifiers.
    /// </summary>
    /// <param name="dateTime">The date and time to convert.</param>
    /// <param name="sourceTimeZoneId">The identifier of the source time zone.</param>
    /// <param name="destinationTimeZoneId">The identifier of the destination time zone.</param>
    /// <returns>
    ///     The date and time in the destination time zone that corresponds to the  parameter in the source time zone.
    /// </returns>
    public static DateTime ConvertTimeBySystemTimeZoneId(this DateTime dateTime, String sourceTimeZoneId, String destinationTimeZoneId)
    {
        return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(dateTime, sourceTimeZoneId, destinationTimeZoneId);
    }
}