[thelist] JavaScript to show and refresh the time of my server

Iván Cervantes lord.icervantes at gmail.com
Thu Aug 27 18:29:00 CDT 2009


Hi!

Im searching for a JavaScript to show and refresh the time of my zope server
in an html page. I have one but sometimes fails in show the seconds
(sometimes show me more than 59).

If anyone can give me a tip or link or code, thanks.

<metal:javascript fill-slot="javascript_head_slot">
          <script type="text/javascript">
        <!-- Start
        function UR_Start(hora, minuto,segundo)
        {
            UR_Nu = new Date;
            serverSegundosTotal=segundo+minuto*60+hora*3600;
            clienteHora=UR_Nu.getHours();
            clienteMinuto=UR_Nu.getMinutes();
            clienteSegundo=UR_Nu.getSeconds();

clienteSegundosTotal=clienteSegundo+clienteMinuto*60+clienteHora*3600;

            diff=serverSegundosTotal - clienteSegundosTotal;

            modificaLabel(diff);
        }

        function showFilled(Value)
        {
            return (Value > 9) ? "" + Value : "0" + Value;
        }
        function modificaLabel(diff)
        {
            UR_Nu = new Date;
            if (diff<0){
               tmp=-diff;}
            else{ tmp=diff;}

            Hr_add=parseInt(tmp / 3600);
            tmp=tmp % 3600;

            Mn_add=parseInt(tmp / 60);
            tmp=tmp % 60;

            Seg_add=tmp;

            if (diff>=0){
                segundos=UR_Nu.getSeconds() + Seg_add;
                if (segundos>=60) { segundos = -(60 - segundos); Mn_add =
Mn_add+1; }

                minutos=UR_Nu.getMinutes() + Mn_add;
                if (minutos>=60 ) { minutos = -(60 - minutos); Hr_add =
Hr_add+1; }

                horas=UR_Nu.getHours()+Hr_add;
                if (horas>=24) { horas = -(24 - horas); }
                }
            else{
                segundos=UR_Nu.getSeconds() - Seg_add;
                if (segundos<0 ) { segundos = (60 - segundos); Mn_add =
Mn_add+1; }

                minutos=UR_Nu.getMinutes() - Mn_add;
                if (minutos<0) { minutos = (60 - minutos); Hr_add =
Hr_add+1; }

                horas=UR_Nu.getHours()-Hr_add;
                if (horas<0) { horas = (24 - horas); }
                }
            UR_Indhold = showFilled(horas) + ":" + showFilled(minutos)+ ":"
+ showFilled(segundos);
            document.getElementById("ur").innerHTML = UR_Indhold;
            setTimeout("modificaLabel("+diff +")",1000);
        }


        // Slut -->
        </script>
      <body onload="UR_Start(); "
         tal:define="toolVotaciones python:here.getToolVotaciones();
                 actualTime python:toolVotaciones.getTime();
                 hora python:actualTime.hour();
                 segundo python:int(actualTime.second());
                 minuto python:actualTime.minute();"
         tal:attributes="onload python:'UR_Start(%s, %s, %s)'% (hora,
minuto, segundo)">


      </body>

    </metal:javascript>

-- 
Iván Cervantes



More information about the thelist mailing list