TimeZoneInfo::ConvertTimeToUtc Method (DateTime)
Converts the specified date and time to Coordinated Universal Time (UTC).
Assembly: mscorlib (in mscorlib.dll)
Parameters
- dateTime
-
Type:
System::DateTime
The date and time to convert.
Return Value
Type: System::DateTimeThe Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime value's Kind property is always set to DateTimeKind::Utc.
| Exception | Condition |
|---|---|
| ArgumentException | TimeZoneInfo.Local.IsInvalidDateTime(dateTime) returns true. |
The exact conversion performed depends on the value of the Kind property of the dateTime parameter, as the following table shows.
DateTime.Kind property | Conversion |
|---|---|
Converts from local time to Coordinated Universal Time (UTC). | |
Assumes dateTime is local time and converts from local time to UTC. | |
Returns dateTime unchanged. |
If dateTime corresponds to an ambiguous local time, this method assumes that it is standard local time. If dateTime corresponds to an invalid local time, the method throws an ArgumentException.
Note |
|---|
If the current computer's local time zone includes multiple adjustment rules, this overload of the ConvertTimeToUtc method can return results that differ from the TimeZone::ToUniversalTime and DateTime::ToUniversalTime methods. TimeZone::ToUniversalTime always applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range. And when executing on .NET Framework 3.5, DateTime::ToUniversalTime also applies the current adjustment rule to time zone conversion, whether or not dateTime lies within its date range. |
If the UTC equivalent of dateTime is earlier than DateTime::MinValue or later that DateTime::MaxValue, this method returns MinValue or MaxValue, respectively.
Notes to Callers:
On Windows XP systems, this method applies only the current adjustment rule to the time zone conversion. 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 illustrates the conversion of time values whose Kind property is DateTimeKind::Utc, DateTimeKind::Local, and DateTimeKind::Unspecified, respectively. It also illustrates the conversion of ambiguous and invalid times.
Available since 3.5
