Switch DateTime To Local Time - CSharp System

CSharp examples for System:DateTime Local

Description

Switch DateTime To Local Time

Demo Code

// Permission is hereby granted, free of charge, to any person
using System.Globalization;
using System.Xml;
using System.IO;/*from   w w  w  . ja va  2s .c  o m*/
using System;

public class Main{
        private static DateTime SwitchToLocalTime(DateTime value)
        {
            switch (value.Kind)
            {
                case DateTimeKind.Unspecified:
                    return new DateTime(value.Ticks, DateTimeKind.Local);

                case DateTimeKind.Utc:
                    return value.ToLocalTime();

                case DateTimeKind.Local:
                    return value;
            }
            return value;
        }
}

Related Tutorials