DateTimeOffset Constructor (DateTime, TimeSpan)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Initializes a new instance of the DateTimeOffset structure using the specified DateTime value and offset.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)


Public Sub New ( _
    dateTime As DateTime, _
    offset As TimeSpan _
public DateTimeOffset(
    DateTime dateTime,
    TimeSpan offset


  • offset
    Type: System.TimeSpan
    The time's offset from Coordinated Universal Time (UTC).


Exception Condition

dateTime.Kind equals Utc and offset does not equal zero.


dateTime.Kind equals Local and offset does not equal the offset of the system's local time zone.


offset is not specified in whole minutes.


offset is less than -14 hours or greater than 14 hours.


UtcDateTime is less than MinValue or greater than MaxValue.


This constructor's behavior depends in part on the value of the Kind property of the dateTime parameter:

Version Notes

XNA Framework

 When this constructor is used in the XNA Framework, it throws a NotSupportedException exception.


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.

Dim localTime As Date = #7/12/2007 6:32:00 AM#
Dim dateAndOffset As New DateTimeOffset(localTime, _
outputBlock.Text &= dateAndOffset.ToString() & vbCrLf
' The code produces the following output:
'    7/12/2007 6:32:00 AM -07:00
DateTime localTime = new DateTime(2007, 07, 12, 06, 32, 00);
DateTimeOffset dateAndOffset = new DateTimeOffset(localTime,
outputBlock.Text += dateAndOffset + "\n";
// The code produces the following output:
//    7/12/2007 6:32:00 AM -07:00

Version Information


Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0


For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.