DateTime To Local Time - CSharp System

CSharp examples for System:DateTime Local

Description

DateTime To Local Time

Demo Code


using System.Configuration;
using System;//from  w w  w  . j av a  2s . c om

public class Main{
        public static DateTime ToLocalTime(this DateTime dt)
        {
            // dt.DateTimeKind should be Utc!
            var tzi = TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
            return TimeZoneInfo.ConvertTimeFromUtc(DateTime.SpecifyKind(dt, DateTimeKind.Utc), tzi);
        }
}

Related Tutorials