0

I'm having a bit of a problem with this. I'm trying to put a clock that uses UTC/ZULU/GMT time no matter what the user machine's timezone is set to. I have no idea when it comes to javascript so I am attempting to use this free script:

<script language="JavaScript">
    function tS(){
        x=newDate(
            tN().getUTCFullYear(),tN().getUTCMonth(),tN().getUTCDate(),
            tN().getUTCHours(),tN().getUTCMinutes(),tN().getUTCSeconds()
        );

        x.setTime(x.getTime());
        return x;
    } 
    function tN(){ return new Date(); } 
    function lZ(x){ return (x>9)?x:'0'+x; } 
    function dT(){
        if(fr==0){
            fr=1; document.write('<font size=4 face=open_sanslight><b>
            <span id="tP">'+eval(oT)+'</span></b></font>');
        }
    document.getElementById('tP').innerHTML=eval(oT); setTimeout('dT()',1000);
    } 
    function y4(x){ return (x<500)?x+1900:x; } 
    var mN=new
    Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'),
    fr=0,oT="lZ(tS().getHours())+':'+lZ(tS().getMinutes())+' '+'<'+'b'+'r'+'>
    '+' '+mN[tS().getMonth()]+' '+tS().getDate()+','+' '+y4(tS().getYear())";
</script>

This displays UTC time perfectly for me because I am on British Summer Time, however if I set my clock one hour forward then the web page clock gets set one hour forward too. I have no idea how I could correct this and so I was wondering if anyone could show me how to do it.

Thanks everyone, I appreciate the help.

Kousik
  • 21,485
  • 7
  • 36
  • 59
user2547576
  • 117
  • 1
  • 9

1 Answers1

0

you could use this time api:

http://www.timeapi.org/

they have an example of how to access it with javascript:

<script type="text/javascript">
  function myCallback(json) {
    alert(new Date(json.dateString));
  }
</script>
<script type="text/javascript" src="http://timeapi.org/utc/now.json?callback=myCallback"
</script>

"however if I set my clock one hour forward then the web page clock gets set one hour forward too" ... the reason this is happening is because your script is being executed by the browser.

SeanPlusPlus
  • 8,663
  • 18
  • 59
  • 84