View Full Version : javascript show different timezones

05-24-2006, 03:53 PM
I am looking for a javascript (if possible) that will display two times from two different time zones at the foot of a page.

Like this:

TWL® NA Time: 5/24/2006 9:01:57 AM
TWL® EU Time: 5/24/2006 3:01:57 PM

If you take a look at this website, and scroll down to the bottom
http://www.teamwarfare.com/ you will se what I mean.

Can that be done with JavaScript, or is that more SS stuff? PHP or ASP maybe?

Any help appreciated.


05-24-2006, 04:43 PM
Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/JavaScript">
//Universal clock 2006
//Genuine code by Corneliu Lucian "KOR" Rusu mailto:corneliulucian(AROND)apropo.ro
var wd=['Sun','Mon','Tue','Wed','Thu','Fri','Sat'];
var D=[
['Bucharest',120,60],//city,standard time zone(minutes), DST(minutes)
['New York',-300,60],
function calc(){
var spans=document.getElementById('zonediv').getElementsByTagName('span')
for(var i=0;i<D.length;i++){
var t=new Date();
t.setTime(t.getTime()+(t.getTimezoneOffset()*60000)+((D[i][1]+D[i][2])*60000));//the zone's time
var Dy=t.getFullYear();
var Dd=t.getDate()<10?'0'+t.getDate():t.getDate();
var Dm=t.getMonth()<10?'0'+(t.getMonth()+1):t.getMonth()+1;
var Dh=t.getHours()<10?'0'+t.getHours():t.getHours();
var Di=t.getMinutes()<10?'0'+t.getMinutes():t.getMinutes();
var Ds=t.getSeconds()<10?'0'+t.getSeconds():t.getSeconds();
var Dz=wd[t.getDay()];
spans[i].firstChild.data=Dh+':'+Di+':'+Ds+' - '+Dz+' '+Dd+'/'+Dm+'/'+Dy;
var root = document.getElementById('zonediv');
for(var i=0;i<D.length;i++){
root.appendChild(document.createTextNode(D[i][0]+' '))
var sp= document.createElement('span');
sp.appendChild(document.createTextNode(' '));


<div id="zonediv">

05-24-2006, 07:56 PM
that was superb Kor, thanks very much!!!

by any chance is there a way to change it that you know that will have only one North American city (Chicago, maybe) and one European city (Paris, say).

thank you!

05-25-2006, 07:11 AM
Of course. all u have to do is to use your own cities/zones in the 2nd degree array

var D=[

The elements in there are
[city/zone, STZ (the Standard time zone), DST (summer hour)]

Simply Google for the STZ and DST for the desired cities. For the momemnt you must enter the code and modify the DST in the day when sities enter/exit DST.

The code migh be improve by seting the DST automatically, according to the days contries enter/exit from DST. I'll think about it

05-25-2006, 10:34 AM
Kor, i'm not getting much back from Google on the STZ and DST thing. Basically, i was looking from Paris STZ and DST as well as maybe Chicago STZ and DST. Have you got a bookmark there that wil give me these?


05-25-2006, 10:53 AM