Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

TimeZoneInfo.ConvertTime Method (DateTime, TimeZoneInfo)

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

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

static member ConvertTime : 
        dateTime:DateTime * 
        destinationTimeZone:TimeZoneInfo -> DateTime

Parameters

dateTime
Type: System.DateTime

The date and time to convert.

destinationTimeZone
Type: System.TimeZoneInfo

The time zone to convert dateTime to.

Return Value

Type: System.DateTime
The date and time in the destination time zone.

ExceptionCondition
ArgumentException

The value of the dateTime parameter represents an invalid time.

ArgumentNullException

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

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

This overload of the ConvertTime(DateTime, TimeZoneInfo) method 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 is TimeZoneInfo.Utc.

DateTimeKind.Utc

The destinationTimeZone is TimeZoneInfo.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.

You can also convert to or from UTC by calling the ConvertTimeFromUtc and ConvertTimeToUtc methods.

Notes to Callers

On Windows XP systems, this method recognizes only the current adjustment rule when performing the conversion if dateTime is treated as a local time or if destinationTimeZone is TimeZoneInfo.Local. As a result, the method may not accurately convert times for periods before the current adjustment rule came into effect. For more information, see the Notes for Callers section in the Local property.

The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. It shows that the source time zone depends on the DateTime.Kind property of the source DateTime value. It also illustrates that the ConvertTime method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010.

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft