System Namespace TimeZone Structure
Returns the coordinated universal time ( UTC ) that corresponds to a specified local time.
[ VB ]
Public Overridable Function ToUniversalTime ( _
time As DateTime _
) As DateTime
[ C# ]
public virtual DateTime ToUniversalTime (
DateTime time
)
[ C++ ]
public:
virtual DateTime ToUniversalTime (
DateTime time
)
[ JScript ]
public function ToUniversalTime (
time : DateTime
) : DateTime
- time
- The local date and time.
A DateTime instance whose value is the UTC time that corresponds to the given time.
Coordinated universal time ( UTC ) was previously known as Greenwich Mean Time (GMT). Local time is the date and time on the computer you are using. Offset is the difference between local time and UTC. That is:
UTC = local time - offset
time must be in the Gregorian calendar and the time zone represented by this instance. If time is in daylight saving time, this method returns the UTC time to the daylight saving time zone. This method obtains the daylight saving time rule from the system.
NOTE: Invoking TimeZone.CurrentTimeZone.ToUniversalTime ( DateTime.Now ) returns the same value as DateTime.UtcNow.
The following example gets the value returned by ToUniversalTime for the current time zone set on the Web server.
Show me
The following examples show how to determine and set the current local time of a user's browser based on the current time zone setting on the Web server.
This is done basically by calling a client-side JavaScript function to determine the current browser's UTC offset based on the time zone setting of the browser, and then calculating the current browser's local time from the UTC time derived from the time zone setting of the server.
TimeZone Members CurrentTimeZone Property GetUtcOffset Method