Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,092
    Thanks
    15
    Thanked 1 Time in 1 Post

    Question javascript show different timezones

    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.

    Picco

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Try this:
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd"
    >
    <
    html>
    <
    head>
    <
    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)
    ['Madrid',60,60],
    [
    'New York',-300,60],
    [
    'Nairobi',180,0]
    ]
    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;
    }
    setTimeout('calc()',1000)
    }
    onload=function(){
    var 
    root document.getElementById('zonediv');
    for(var 
    i=0;i<D.length;i++){
    root.appendChild(document.createTextNode(D[i][0]+' '))
    var 
    spdocument.createElement('span');
    sp.appendChild(document.createTextNode(' '));
    root.appendChild(sp);root.appendChild(document.createElement('br'))
    }
    calc();
    }
    </script>

    </head>

    <body>
    <div id="zonediv">
    </div>
    </body>
    </html> 
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,092
    Thanks
    15
    Thanked 1 Time in 1 Post
    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!

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    Senior Coder crmpicco's Avatar
    Join Date
    Jan 2005
    Location
    Mauchline, Scotland
    Posts
    1,092
    Thanks
    15
    Thanked 1 Time in 1 Post
    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?

    Picco

  • #6
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •