To Universal Time - CSharp System

CSharp examples for System:DateTime Format

Description

To Universal Time

Demo Code


using System;/*from  ww  w .j a  va2 s  .co m*/

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

Related Tutorials