Results 1 to 10 of 10

Thread: Same time no matter zone?

  1. #1
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Same time no matter zone?

    im looking for a time script to display the time no matter the zone

    Heres my current script
    I can change the time. but other people in other time zones see it differnt still
    Code:
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////Customization///////////////////////////////////
    
    	//Set the separator between the time hours, mins, and seconds
    	//Set the Time bgcolor to change its color background
    	//Set the 12 hour to 1 to only go to 12 and display am and pm
    	var myTime_spacer = ":"
    	var myTime_bgcolor = "white"
    	var myTime_Image = ""
    	var myTime_12 = 1;
    	
    	//Put more by a / Example: Verdana, Arial, Helvetica, sans-serif
    	//Not all computers got the same fonts. so putting more would make your clock look better
    	//Set the Size it you want A size of Text. +1 and -5 numbers work also
    	var myFont_Face = "Verdana"
    	var myFont_Size = "+4"
    	var myFont_color = "White"
    
    
    ////////////////////////////END Customization///////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////TIME SCRIPT///////////////////////////////////
    /////////////////////DO NOT EDIT THIS! YOU MIGHT BREAK IT///////////////////////
    
    var isNav=(navigator.appName.indexOf("Netscape")!=-1);
    
    var localTime = new Date();
    var myTime = new Date();
    
    var hoursOffset = Math.floor(localTime.getTimezoneOffset() / 60);
    /* Pacific is +17  Mountain is +18  Central is +19  East is +20 */
    myTime.setHours(localTime.getHours() + hoursOffset - 0);
    myTime.setMinutes(localTime.getMinutes());
    
    var timeHour = myTime.getHours();
    var timeMinute = myTime.getMinutes();
    var timeSecond = myTime.getSeconds();
    
    function startClock() {
    
      setInterval("updateClock()",0);
    
    }
    
    function doubleDigits(digits) {
    
      if (digits < 10) digits = "0" + digits;
      return(digits);
      
    }
    
    var page_loaded; // set true onload (avoid errors onmouseover/out before page loaded)
    
    function writeToLayer(id, sHTML) {
    //  if (!page_loaded) return;
      var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
      if (!el) return;
      var cntnt = '<div class="myTime">' + sHTML + '</div>';
      if (typeof el.innerHTML!="undefined") {
          el.innerHTML = cntnt;
      } else if (document.layers) {
    			el.document.write(cntnt);
    			el.document.close();
      }
    }
    
    function updateClock() {
      
      timeSecond++;
      if (timeSecond >= 60) {
        timeSecond = timeSecond - 60;
        timeMinute++;
      }
      if (timeMinute >= 60) {
        timeMinute = timeMinute - 60;
        timeHour++;
      }
    //  if (timeHour >= 12) {
    //    timeHour = timeHour - 12;
    //	timeHour++;
    	if (myTime_12) {
    		dn = " AM";
    		if (timeHour > 11) { dn = " PM"; timeHour = timeHour - 12; }
    		if (timeHour == 0) { timeHour = 12; }
    	} else {
    		dn = " Militray Time";
    
    
      }
      
      timeString = doubleDigits(timeHour) +myTime_spacer + doubleDigits(timeMinute) +dn;
      formattedTime = '<font size='+myFont_Size+'><div style="background-color: '+myTime_bgcolor+'; background-image:  url('+myTime_Image+'); layer-background-image:  url('+myTime_Image+');">' + timeString + '</div>';
      writeToLayer('TimeLayer',formattedTime);
      
    }

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Not sure exactly want you are going for here. You should be aware that any javascript relies upon the user's system clock. If it is set wrong, the script will reflect that. If it is set to a different time zone, the script will reflect that. This script appears to adjust the time displayed to Universal Time (aka GMT). If the script is working as it seems to be intended and all user's system clocks are set correctly, all users should see the same Universal Time time at any given moment. What kind of variations have you been seeing? How can you change the time?

    Anyways, I tried out this script and it appears to do nothing, what did you leave out, some targeted code for the body section?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i am able to make the clock apear to change its hours by changing these variables:
    var hoursOffset = Math.floor(localTime.getTimezoneOffset() / 60);
    myTime.setHours(localTime.getHours() + hoursOffset - 0);

    but when i changed the 60 to 1 and left the other number 0 it came up with my computers time.
    therefor i am wondering if its really getting the GMT time or not.
    i would like it to so i can set it to get the time of a place.

    go ahead and download and use the script and firgure out as long as it will work of gmt time instead of user time.

    it would be ok if it worked off the Servers time instead i dont care i just want it so no matter where you are you see the same time it is in a certain time zone.

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jay3ld
    go ahead and download and use the script and firgure out
    I would but, as far as I can tell, you've provided no information that would allow me to do so. Where is the full version of this script located? What time zone are you in? It could be important.

    BTW, have you seen this?

    http://www.maxxblade.co.uk/clock/

    You might have better luck abandoning your current script a making a custom one using the clock script generator at the above address.
    Last edited by jscheuer1; 05-13-2005 at 05:18 AM.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok. i live in pacific time zone but thats not what time i want to set it to

    i want to set it to the maui time for a webpage i am working on:
    http://mauicondo101.com/
    Last edited by jay3ld; 05-13-2005 at 02:44 PM.

  6. #6
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ok. after a using that script of that webpage you sent i got it to use GMT time. Finally!!!


    but i started to edit and now got errors
    i want it so i can set it to differnt times by setting differnt variables.

    Heres the script thats supposed to change the time when just changing the variable

    Code:
    var Time_offset=T2
    function MyTime_offset(){
    	if Time_offset==T1
    		{T1=54000000}
    	if Time_offset==T2
    		{T2=61200000}

    Heres whats doing the time chaning

    Code:
    //Edit the Time here 
    function daylightSaving(){
       return ((timeNow().getTime()>findDay(0,3,1,1).getTime())&&(timeNow().getTime()<findDay(0,9,1,-1).getTime()))?+MyTime_offset:0;
    }



    Heres my full script. Some var commands were // out because i am functioning them to do other stuff more easy.

    Code:
    //////////////////////////////////////////////////////////////////////
    //////////////CUSTOMIZATION///////////////////////////////////////////
    var MyhtmlStart = "<table><tr><td width=50%><hr size='5' id='HRRULE'> Todays Date:"
    var Myhtmlend = "<hr size='5' id='HRRULE'></td><td widht=50%></td></tr></table>"
    var Mytime_PM = "PM"
    var Mytime_AM = "AM"
    var MyTime_leadzero = "0"
    //Time off set will change the time by 3600000 
    //Time off set for Eastern Time is: 72000000
    //Time off set for Central time is 68400000
    //Time off set for Mountain Time is: 64800000
    //Time off set for Pacific Time is: 61200000
    //Time off set for Hawaii Time is: 54000000
    //var MyTime_offset = "54000000"
    var Time_offset=T2
    function MyTime_offset(){
    	if Time_offset==T1
    		{T1=54000000}
    	if Time_offset==T2
    		{T2=61200000}
    		
    ///////////////END OF CUSTOMIZATION///////////////////////////////////
    //////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////
    ///////DONT EDIT BELOW THIS LINE OR IT HAS THE CHANCE OF NOT WORKING//
    /////////////////////I MEAN IT////////////////////////////////////////
    function timeSource(){
       x=new Date(timeNow().getUTCFullYear(),timeNow().getUTCMonth(),timeNow().getUTCDate(),timeNow().getUTCHours(),timeNow().getUTCMinutes(),timeNow().getUTCSeconds());
       x.setTime(x.getTime()+daylightSaving()+0);
       return x;
    }
    function timeNow(){
       return new Date();
    }
    //Edit the Time here 
    function daylightSaving(){
       return ((timeNow().getTime()>findDay(0,3,1,1).getTime())&&(timeNow().getTime()<findDay(0,9,1,-1).getTime()))?+MyTime_offset:0;
    }
    	
    function findDay(d,m,h,p){
       var week=(p<0)?7*(p+1):7*(p-1),nm=(p<0)?m+1:m,x=new Date(timeNow().getUTCFullYear(),nm,1,h,0,0),dOff=0;
       if(p<0){
          x.setTime(x.getTime()-86400000);
       }
       if(x.getDay()!=d){
          dOff=(x.getDay()<d)?(d-x.getDay()):0-(x.getDay()-d);
          if(p<0&&dOff>0){
             week-=7;
          }
          if(p>0&&dOff<0){
             week+=7;
          }
          x.setTime(x.getTime()+((dOff+week)*86400000));
       }
       return x;
    }
    function leadingZero(x){
    	return (x>9)?x: MyTime_leadzero+x;
    }
    
    function twelveHour(x){
       if(x==0){
          x=12;
       }
       return (x>12)?x-=12:x;
    }
    function dateEnding(x){
       if(x==1||x==21||x==31){
          return 'st';
       }
       if(x==2||x==22){
          return 'nd';
       }
       if(x==3||x==23){
          return 'rd';
       }
       return 'th';
    }
    function displayTime(){
       if(fr==0){
          fr=1;
          document.write(MyhtmlStart+' '+' <span id="tP">'+eval(outputTime)+'</span>'+' '+Myhtmlend);
       }
       tP.innerText=eval(outputTime);
       setTimeout('displayTime()',1000);
    }
    function amPMsymbol(x){
       return (x>11)?Mytime_PM:Mytime_AM;
    }
    function fixYear4(x){
       return (x<500)?x+1900:x;
    }
    var monthNames=new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
    var fr=0;
    var outputTime="twelveHour(timeSource().getHours())+':'+leadingZero(timeSource().getMinutes())+':'+leadingZero(timeSource().getSeconds())+' '+amPMsymbol(timeSource().getHours())+' '+'of'+' '+monthNames[timeSource().getMonth()]+' '+timeSource().getDate()+dateEnding(timeSource().getDate())+' '+fixYear4(timeSource().getYear())";

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jay3ld
    Code:
    var Time_offset=T2
    function MyTime_offset(){
    	if Time_offset==T1
    		{T1=54000000}
    	if Time_offset==T2
    		{T2=61200000}
    Who wrote that? The script generator or you? I could be wrong here but, it makes no sense to me. Doesn't it give an error 'T2 is not defined'? It may just skip it or not run at all because there is no closing '}' to the function. I'd write it like this:
    Code:
    var T1=54000000, T2=61200000, MyTime_offset=T2;
    and then just change T2 to T1 to change zones or make a statement elsewhere (it will have to be after the above statement) that will.

    One thing I don't get here at all is - why bother with this at all? Are you trying to dynamically change the offset? If so, depending on what?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i wrote it. i guess im bad at that.

    ill try your var thing hope it works.

    i got a choice of webservers and were they are located is all differnt. and i might use this on more than one webpage. so i want to be able to change it easy.

    Just tried your script. it runs and works. Thanks.
    Last edited by jay3ld; 05-18-2005 at 03:06 PM.

  9. #9
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,496
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by jay3ld
    i wrote it. i guess im bad at that.
    Well, don't feel too bad, at least it was clear enough for me to see what you were trying to do, and consider it was the last thing I looked at before I went to sleep. I didn't mean to sound so critical, I guess I was thinking like a script interpreter at that point. I've written some really wacked code myself, we learn more from our mistakes. Glad it now does what you wanted. Your approach could work if the logic was laid out differently and your function returned the value in question. That is frequently used but, more involved than necessary for this case.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #10
    Join Date
    Dec 2004
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks.

    i prefected the script so now it dont need the big numbers at all and runs better to.

    again thanks for the help.

Bookmarks

Posting Permissions

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