TimeZoneInfo::ConvertTimeToUtc Method (DateTime, TimeZoneInfo)
Converts the time in a specified time zone to Coordinated Universal Time (UTC).
Assembly: mscorlib (in mscorlib.dll)
public: static DateTime ConvertTimeToUtc( DateTime dateTime, TimeZoneInfo^ sourceTimeZone )
Parameters
- dateTime
- Type: System::DateTime
The date and time to convert.
- sourceTimeZone
- Type: System::TimeZoneInfo
The time zone of dateTime.
Return Value
Type: System::DateTimeThe Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime object's Kind property is always set to DateTimeKind::Utc.
| Exception | Condition |
|---|---|
| ArgumentException | dateTime.Kind is DateTimeKind::Utc and sourceTimeZone does not equal TimeZoneInfo::Utc. -or- dateTime.Kind is DateTimeKind::Local and sourceTimeZone does not equal TimeZoneInfo::Local. -or- sourceTimeZone.IsInvalidDateTime(dateTime) returns true. |
| ArgumentNullException | sourceTimeZone is nullptr. |
If the Kind property of the dateTime parameter equals DateTimeKind::Utc and the sourceTimeZone parameter equals TimeZoneInfo::Utc, this method returns dateTime without performing any conversion.
If dateTime corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If dateTime corresponds to an invalid time, this method throws an ArgumentException.
If the Coordinated Universal Time (UTC) equivalent of dateTime is earlier than DateTime::MinValue or later that DateTime::MaxValue, this method returns MinValue or MaxValue, respectively.
Notes to CallersOn Windows XP systems, the method applies only the current adjustment rule to the time zone conversion if sourceTimeZone 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.
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.