Export (0) Print
Expand All

TimeZone.ToUniversalTime Method

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

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

public virtual DateTime ToUniversalTime(
	DateTime time
)

Parameters

time
Type: System.DateTime

A date and time.

Return Value

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

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

NoteNote

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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft