C# DateTimeOffset DateTimeOffset(DateTime, TimeSpan)

Description

DateTimeOffset DateTimeOffset(DateTime, TimeSpan) initializes a new instance of the DateTimeOffset structure using the specified DateTime value and offset.

Syntax

DateTimeOffset.DateTimeOffset(DateTime, TimeSpan) has the following syntax.


public DateTimeOffset(
  DateTime dateTime,
  TimeSpan offset
)

Parameters

DateTimeOffset.DateTimeOffset(DateTime, TimeSpan) has the following parameters.

  • dateTime - A date and time.
  • offset - The time's offset from Coordinated Universal Time (UTC).

Example

The following example shows how to initialize a DateTimeOffset object with a date and time and the offset of the local time zone when that time zone is not known in advance.


using System;/*ww  w .ja v a 2  s. com*/

public class MainClass{
  public static void Main(String[] argv){  
    DateTime localTime = new DateTime(2014, 07, 12, 06, 32, 00); 
    DateTimeOffset dateAndOffset = new DateTimeOffset(localTime, 
                             TimeZoneInfo.Local.GetUtcOffset(localTime));
    Console.WriteLine(dateAndOffset);

  }
}

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