DateTimeOffset Constructor (DateTime, TimeSpan)
Initializes a new instance of the DateTimeOffset structure using the specified DateTime value and offset.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- dateTime
-
Type:
System::DateTime
A date and time.
- offset
-
Type:
System::TimeSpan
The time's offset from Coordinated Universal Time (UTC).
| Exception | Condition |
|---|---|
| ArgumentException | |
| 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:
If the value of Kind is DateTimeKind::Utc, the value of the offset parameter must be 0 or an ArgumentException is thrown.
If the value of Kind is DateTimeKind::Local, the value of the offset parameter must be equal to the local time zone's offset from Coordinated Universal Time (UTC) for that particular date or an ArgumentException is thrown.
If the value of Kind is DateTimeKind::Unspecified, the offset parameter can have any valid value.
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.
Available since 8
.NET Framework
Available since 2.0
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1