This documentation is archived and is not being maintained.

DateTimeOffset Constructor (DateTime, TimeSpan)

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 _
Dim dateTime As DateTime 
Dim offset As TimeSpan 

Dim instance As New DateTimeOffset(dateTime, _


Type: System.DateTime

A date and time.

Type: System.TimeSpan

The time's offset from Coordinated Universal Time (UTC).


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:

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 = #07/12/2007 6:32AM#
Dim dateAndOffset As New DateTimeOffset(localTime, _
' The code produces the following output: 
'    7/12/2007 6:32:00 AM -07:00

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1