Default DateTime To Utc - CSharp System

CSharp examples for System:DateTime UTC

Description

Default DateTime To Utc

Demo Code


using System;//from  w  ww .  ja  v  a 2 s .c o m

public class Main{
        public static DateTime? DefaultToUtc(DateTime? date)
        {
            return date.HasValue && date.Value.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(date.Value, DateTimeKind.Utc) : date;
        }
        public static DateTime DefaultToUtc(DateTime date)
        {
            return date.Kind == DateTimeKind.Unspecified ? DateTime.SpecifyKind(date, DateTimeKind.Utc) : date;
        }
}

Related Tutorials