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:

  1. The local time on the use's computer
  2. UTC
  3. Unspecified

A DateTimeOffset stores the offset from UTC as a TimeSpan:

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
)

ParametersTypeMeaning
yearSystem.Int32The year (1 through 9999).
monthSystem.Int32The month (1 through 12).
daySystem.Int32The day (1 through the number of days in month).
hourSystem.Int32The hours (0 through 23).
minuteSystem.Int32The minutes (0 through 59).
secondSystem.Int32The seconds (0 through 59).
millisecondSystem.Int32The 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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.