Share via


TimeZoneInfo.ConvertTime Method (DateTime, TimeZoneInfo)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Shared Function ConvertTime ( _
    dateTime As DateTime, _
    destinationTimeZone As TimeZoneInfo _
) As DateTime
public static DateTime ConvertTime(
    DateTime dateTime,
    TimeZoneInfo destinationTimeZone
)

Parameters

Return Value

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

Exceptions

Exception Condition
ArgumentException

The value of the dateTime parameter represents an invalid time.

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 determines the source time zone from the value of the dateTime parameter's Kind property, as the following table shows.

Kind property value

Source time zone

Method behavior

DateTimeKind.Local

Local

Converts the local time to the time in destinationTimeZone.

DateTimeKind.Utc

Utc

Converts Coordinated Universal Time (UTC) to the time in destinationTimeZone.

DateTimeKind.Unspecified

Assumed to be Local.

Converts the local time to the time in destinationTimeZone.

The Kind property of the returned DateTime value is set as shown in the following table.

Condition

Returned Kind property value

The destinationTimeZone parameter is TimeZoneInfo.Utc.

DateTimeKind.Utc

The Kind property of dateTime is DateTimeKind.Local and destinationTimeZone is DateTimeKind.Local.

DateTimeKind.Local

All other date and time values and destination time zones.

DateTimeKind.Unspecified

If the value of the dateTime parameter is an ambiguous local time, it is interpreted as a standard time. If the dateTime parameter is an invalid local time, this method throws an ArgumentException.

If the conversion of dateTime results in a date and time value that is earlier than DateTime.MinValue or later than DateTime.MaxValue, this method returns DateTime.MinValue or DateTime.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.