Export (0) Print
Expand All

DateTimeOffset::ToOffset Method

Converts the value of the current DateTimeOffset object to the date and time specified by an offset value.

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

public:
DateTimeOffset ToOffset(
	TimeSpan offset
)

Parameters

offset
Type: System::TimeSpan

The offset to convert the DateTimeOffset value to.

Return Value

Type: System::DateTimeOffset
A DateTimeOffset 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.

ExceptionCondition
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.

No code example is currently available or this language may not be supported.

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

Community Additions

ADD
Show:
© 2014 Microsoft