To Local Time - CSharp System

CSharp examples for System:DateTime Local

Description

To Local Time

Demo Code


using System;/* ww  w . jav a  2 s.  c om*/

public class Main{
        public static DateTime ToLocalTime(this DateTime utcDateTime, string timeZoneId) {
            var date = DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified);
            return TimeZoneInfo.ConvertTimeFromUtc(date, TimeZoneInfo.FindSystemTimeZoneById(timeZoneId));
        }
        public static DateTime ToLocalTime(this DateTime utcDateTime, TimeZoneInfo timeZoneInfo) {
            var date = DateTime.SpecifyKind(utcDateTime, DateTimeKind.Unspecified);
            return TimeZoneInfo.ConvertTimeFromUtc(date, timeZoneInfo);
        }
}

Related Tutorials