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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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:


The Network for Technology Professionals

Search:

About Internet.com

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

webref The latest from WebReference.com Browse >
Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2 · Create Multilingual Web Sites with Windows Unicode Fonts
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Telehealth Takes Hold In Upstate New York · Ten Wi-Fi Security Threats to Monitor · SanDisk's SSD As Rapid As It Is Reliable