DateTimeOffset Constructor (DateTime, TimeSpan)

DateTimeOffset Constructor (DateTime, TimeSpan)

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

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

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

'Declaration
Public Sub New ( _
	dateTime As DateTime, _
	offset As TimeSpan _
)

Parameters

dateTime
Type: System.DateTime
A date and time.
offset
Type: System.TimeSpan
The time's offset from Coordinated Universal Time (UTC).

ExceptionCondition
ArgumentException

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

-or-

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

-or-

offset is not specified in whole minutes.

ArgumentOutOfRangeException

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

-or-

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, _
                         TimeZoneInfo.Local.GetUtcOffset(localTime))
outputBlock.Text &= dateAndOffset.ToString() & vbCrLf
' The code produces the following output:
'    7/12/2007 6:32:00 AM -07:00


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2017 Microsoft