TimeZoneInfo::ConvertTime Method (DateTimeOffset, TimeZoneInfo)
Converts a time to the time in a particular time zone.
Assembly: mscorlib (in mscorlib.dll)
public: 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 ValueType: System::DateTimeOffset
The date and time in the destination time zone.
The value of the destinationTimeZone parameter is nullptr.
When performing the conversion, the 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.
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.