spacer
Yehuda Shiran July 11, 2000
Local Times Around the World
Tips: July 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

First thing you need to do is gather the local times in the cities you are interested in, wrt GMT. Here is the list we use in our example:

var London = 1;
var Moscow = 3;
var NewDelhi = 5.5; 
var Tokyo = 9;
var LA = -7;
var NewYork = -4;
var Beijing = 8;
var WashingtonDC = -4;

Next, we create the Date object:

now = new Date();

and then the GMT:

var ar1 = now.toGMTString().split(" ");

Since we need to manipulate the hour part of the GMT, we split the string and store its parts in ar1. We then take the time part and split it into ar2. The hour part is the first element of the array ar2:

var ar2 = ar1[4].split(":");

Now, we are ready to adjust the GMT hour for the Daylight Saving Time difference, denoted as GMT:

var GMThour = parseInt(ar2[0]) + GMT;

For each city, we crate a current Date object:

now = new Date();

set the hours according the GMT and the given offset:

now.setHours(GMThour + Moscow);

and then write the date according to the local format definitions:

document.write("Moscow:  " + now.toLocaleString()); document.write("<BR>");

Press here to see the local time in cities around the world.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business