Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TimeZoneInfo::ConvertTimeToUtc Method (DateTime)

 

Converts the specified date and time to Coordinated Universal Time (UTC).

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

public:
static DateTime ConvertTimeToUtc(
	DateTime dateTime
)

Parameters

dateTime
Type: System::DateTime

The date and time to convert.

Return Value

Type: System::DateTime

The 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

DateTimeKind::Local

Converts from local time to Coordinated Universal Time (UTC).

DateTimeKind::Unspecified

Assumes dateTime is local time and converts from local time to UTC.

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

System_CAPS_noteNote

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.

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

.NET Framework
Available since 3.5
Return to top
Show:
© 2017 Microsoft