Returns the Coordinated Universal Time (UTC) that corresponds to a specified time.
Assembly: mscorlib (in mscorlib.dll)
abstract ToUniversalTime : time:DateTime -> DateTime override ToUniversalTime : time:DateTime -> DateTime
- Type: System.DateTime
A date and time.
If the local time zone observes daylight saving time, applies the current adjustment rule to the time parameter when performing the conversion.
The 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 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.