TimeZoneInfo::ConvertTime Method (DateTimeOffset, TimeZoneInfo^)


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

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

static DateTimeOffset ConvertTime(
	DateTimeOffset dateTimeOffset,
	TimeZoneInfo^ destinationTimeZone


Type: System::DateTimeOffset

The date and time to convert.

Type: System::TimeZoneInfo^

The time zone to convert dateTime to.

Return Value

Type: System::DateTimeOffset

The date and time in the destination time zone.

Exception Condition

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

Notes to Callers:

On Windows XP systems, this method applies only the current adjustment rule to the time zone conversion if dateTimeOffset 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 DateTimeOffset values to times in the Eastern Time zone of the U.S. and Canada. It 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.

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top