DateTimeOffset::ToOffset Method
Converts the value of the current DateTimeOffset object to the date and time specified by an offset value.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- offset
- Type: System::TimeSpan
The offset to convert the DateTimeOffset value to.
Return Value
Type: System::DateTimeOffsetAn object that is equal to the original DateTimeOffset object (that is, their ToUniversalTime methods return identical points in time) but whose Offset property is set to offset.
| Exception | Condition |
|---|---|
| ArgumentException | The resulting DateTimeOffset object has a DateTime value earlier than MinValue. -or- The resulting DateTimeOffset object has a DateTime value later than MaxValue. |
| ArgumentOutOfRangeException | offset is less than -14 hours. -or- offset is greater than 14 hours. |
The ToOffset method is an alternative to calling the TimeZoneInfo::ConvertTime(DateTimeOffset, TimeZoneInfo) method. It can be useful for performing simple conversions from one time zone to another when the time zones' offsets from Coordinated Universal Time (UTC) are known. However, because neither the original DateTimeOffset object nor the new DateTimeOffset object returned by the method call are unambiguously related to a particular time zone, the method does not apply any time zone adjustment rules in the conversion.
The following example illustrates how to use the ToOffset method to convert a DateTimeOffset object to a DateTimeOffset object with a different offset.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.