TimeZoneInfo.ConvertTime Method (DateTimeOffset, TimeZoneInfo)

Converts a time to the time in a particular time zone.

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

Syntax

'Declaration
Public Shared Function ConvertTime ( _
    dateTimeOffset As DateTimeOffset, _
    destinationTimeZone As TimeZoneInfo _
) As DateTimeOffset
public static DateTimeOffset ConvertTime(
    DateTimeOffset dateTimeOffset,
    TimeZoneInfo destinationTimeZone
)

Parameters

Return Value

Type: System.DateTimeOffset
A DateTimeOffset value that represents the date and time in the destination time zone.

Exceptions

Exception Condition
ArgumentNullException

The value of the destinationTimeZone parameter is nulla null reference (Nothing in Visual Basic).

Remarks

When performing the conversion, the ConvertTime(DateTimeOffset, TimeZoneInfo) method applies any adjustment rules in effect in the destinationTimeZone time zone.

This overload differs from the other overloads of the ConvertTime method by accepting a DateTimeOffset value as its first parameter. This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. As a result, the dateTimeOffset parameter cannot represent either an ambiguous time or an invalid time.

In converting the dateTimeOffset value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone.

If the conversion of dateTimeOffset results in a date and time value that is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue, this method returns DateTimeOffset.MinValue or DateTimeOffset.MaxValue, respectively.

Version Notes

XNA Framework

 When this method is used in the XNA Framework, it throws a NotSupportedException exception.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.