Changes

JavaScript Date Object

609 bytes added, 18:34, 8 May 2007
Finding the Time Zone Offset and Getting Local Time
== Finding the Time Zone Offset and Getting Local Time ==
It is often useful to be able to find out the time zone offset (meaning the number of hours ahead or behind UTC) of a web site visitor. JavaScript provides the ''getTimezoneOffset()'' method which, as the name suggests, returns the number of minutes difference between the client (i.e where the browser is being run) and UTC:
<pre>
</pre>
 
The local time of the system on which the browser is running can be obtained using the ''toLocaleString()'' method of the JavaScript Date Object. This method returns a string correct for the lcoal time zone. Assuming, once again, a visitor located on the East coast of the United States and the following the following script fragment:
 
<pre>
 
var myDate = new Date (); // Get the date of the user's system
 
document.write ("Local Time is " + myDate.getLocaleTime());
 
</pre>
 
you should expect to receive output as follows:
 
Wed 20 Jun 2007 12:00:00 PM EDT