C# DateTimeOffset DateTimeOffset(DateTime)

Description

DateTimeOffset DateTimeOffset(DateTime) initializes a new instance of the DateTimeOffset structure using the specified DateTime value.

Syntax

DateTimeOffset.DateTimeOffset(DateTime) has the following syntax.


public DateTimeOffset(
  DateTime dateTime
)

Parameters

DateTimeOffset.DateTimeOffset(DateTime) has the following parameters.

  • dateTime - A date and time.

Example

The following example illustrates how the value of the DateTime.Kind property of the dateTime parameter affects the date and time value that is returned by this constructor.


using System;/*from  ww w  .j av  a 2  s  . com*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTime localNow = DateTime.Now;
    DateTimeOffset localOffset = new DateTimeOffset(localNow);
    Console.WriteLine(localOffset.ToString());
    
    DateTime utcNow = DateTime.UtcNow;
    DateTimeOffset utcOffset = new DateTimeOffset(utcNow);
    Console.WriteLine(utcOffset.ToString());
    
    DateTime unspecifiedNow = DateTime.SpecifyKind(DateTime.Now, 
                                   DateTimeKind.Unspecified);
    DateTimeOffset unspecifiedOffset = new DateTimeOffset(unspecifiedNow);
    Console.WriteLine(unspecifiedOffset.ToString());

  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version