I am using the following code to display the current time of the server:
<p id="demo"></p>
<script>
function segundoAtual() {
var n = <?php
date_default_timezone_set('America/Sao_Paulo');
$cH = date('G');
$cM = date('i');
$cS = date('s');
echo ($cH*60*60)+($cM*60)+$cS;
?>;
var segundosInicio = inicioYujiaLynxA+(-difLynx);
c = (( n - segundosInicio + duraYujia ) % duraYujia ) / duraYujia;
i = Math.floor((mapYujia.length * 2 - 2) * c);
if( i >= mapYujia.length ) i = mapYujia.length * 2 - i - 1;
var pin = document.getElementById('pin');
pin.style.left = (mapYujia[i][0]/600*100) + '%';
pin.style.top = (mapYujia[i][1]/757*100) + '%';
}
segundoAtual();
setInterval(segundoAtual, 1);
</script>
The variables segundosInicio
, inicioYujiaLynxA
and difLynx
are defined in another file, called by <script src="servers.js"></script>
at the beginning of the document.
The variable segundoAtual
defines the position of an element (pin) on a map ...
The result is obtained in seconds since midnight today.
Or is setInterval not running to update the time, or can the variable only be refreshed if the page is reloaded?