TimeZoneInfo.ConvertTime Method (DateTime, TimeZoneInfo)
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Converts a time to the time in a particular time zone.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- dateTime
- Type: System.DateTime
The date and time to convert.
- destinationTimeZone
- Type: System.TimeZoneInfo
The time zone to convert dateTime to. It must be either TimeZoneInfo.Local or TimeZoneInfo.Utc.
Return Value
Type: System.DateTimeA DateTime value that represents the date and time in the destination time zone.
| Exception | Condition |
|---|---|
| ArgumentException | The value of the dateTime parameter represents an invalid time. |
| ArgumentNullException | The value of the destinationTimeZone parameter is null. |
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 |
|---|---|---|
Converts the local time to the time in destinationTimeZone. | ||
Converts Coordinated Universal Time (UTC) to the time in destinationTimeZone. | ||
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. | |
The Kind property of dateTime is DateTimeKind.Local and destinationTimeZone is DateTimeKind.Local. | |
All other date and time values and destination time zones. |
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.