C# DateTime Kind
Description
DateTime Kind
gets a value that indicates whether the
time represented by this instance is based on local time, Coordinated Universal
Time (UTC), or neither.
Syntax
DateTime.Kind
has the following syntax.
public DateTimeKind Kind { get; }
Example
The following example uses the SpecifyKind method to demonstrate how the Kind property influences the ToLocalTime and ToUniversalTime conversion methods.
using System;//from www . j ava 2 s .c om
class Sample
{
public static void Main()
{
DateTime saveNow = DateTime.Now;
DateTime saveUtcNow = DateTime.UtcNow;
DateTime myDt;
myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Utc);
Display("Utc: .............", myDt);
}
public static string datePatt = @"M/d/yyyy hh:mm:ss tt";
public static void Display(string title, DateTime inputDt)
{
DateTime dispDt = inputDt;
string dtString;
dtString = dispDt.ToString(datePatt);
Console.WriteLine("{0} {1}, Kind = {2}",
title, dtString, dispDt.Kind);
}
}
The code above generates the following result.