asp.net.ph

TimeZone.ToUniversalTime Method

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

Parameters

time
The local date and time.

Return Value

A DateTime instance whose value is the UTC time that corresponds to the given time.

Remarks

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.

Example

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.ToUniversalTime Example
Run Sample | View Source
Localization Resource Fallback
Run Sample | View Source
See Also

TimeZone Members   CurrentTimeZone Property   GetUtcOffset Method Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph