Mega Code Archive

 
Categories / C# Book / 02 Essential Types
 

0262 DateTime and DateTimeOffset

DateTime can be specified relative to local time, UTC, or unspecified. DateTime and DateTimeOffset DateTime and DateTimeOffset differ in how they handle time zones. A DateTime incorporates a three-state flag indicating whether the DateTime is relative to: The local time on the use's computer UTC Unspecified A DateTimeOffset stores the offset from UTC as a TimeSpan: DateTime ignores the three-state flag in comparisons. DateTime considers two values equal if they have the same value. DateTimeOffset considers two values equal if they refer to the same point in time. Initializes a new instance of the DateTime structure to the specified year, month, day, hour, minute, second, and millisecond. Syntax public DateTime( int year, int month, int day, int hour, int minute, int second, int millisecond ) Parameters Type Meaning year System.Int32 The year (1 through 9999). month System.Int32 The month (1 through 12). day System.Int32 The day (1 through the number of days in month). hour System.Int32 The hours (0 through 23). minute System.Int32 The minutes (0 through 59). second System.Int32 The seconds (0 through 59). millisecond System.Int32 The milliseconds (0 through 999). using System; using System.Collections; using System.Collections.ObjectModel; using System.Collections.Specialized; using System.Collections.Generic; using System.Linq; using System.Reflection; class Program { static void Main() { DateTime date1 = new DateTime(2010, 8, 18, 16, 32, 18, 500); Console.WriteLine(date1.ToString("M/dd/yyyy h:mm:ss.fff tt")); } } The output: 8/18/2010 4:32:18.500 PM