Breyta

Deila með


TimeZone.ToUniversalTime(DateTime) Method

Definition

Returns the Coordinated Universal Time (UTC) that corresponds to a specified time.

public:
 virtual DateTime ToUniversalTime(DateTime time);
public virtual DateTime ToUniversalTime (DateTime time);
abstract member ToUniversalTime : DateTime -> DateTime
override this.ToUniversalTime : DateTime -> DateTime
Public Overridable Function ToUniversalTime (time As DateTime) As DateTime

Parameters

time
DateTime

A date and time.

Returns

A DateTime object whose value is the Coordinated Universal Time (UTC) that corresponds to time.

Remarks

If the local time zone observes daylight saving time, ToUniversalTime applies the current adjustment rule to the time parameter when performing the conversion.

Note

The ToUniversalTime method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the Coordinated Universal Time (UTC) corresponding to a particular local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if time is a historic date and time value that was subject to a previous adjustment rule.

If the time parameter is an ambiguous time, the method assumes that it is a standard time. (An ambiguous time is one that can map either to a standard time or to a daylight saving time in the local time zone.) If time is an invalid time, the method simply subtracts the local time from the local time zone's UTC offset to return UTC. (An invalid time is one that does not exist because of the application of daylight saving time adjustment rules.)

Because time is interpreted in relation to the current time zone on the current system, the date and time returned by this method can differ if an application is run on different computers or on the same computer with different time zones. For cases in which a date and time value must represent a single, unambiguous point in time, use a DateTimeOffset value to represent the local time.

The ToUniversalTime method corresponds to the TimeZoneInfo.ConvertTimeToUtc(DateTime) method overload with a DateTime parameter whose Kind property does not equal DateTimeKind.Utc. Whenever possible, use the TimeZoneInfo.ConvertTimeToUtc(DateTime) method overload.

Applies to

See also