0
I am using the following code to display the current server time:
<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 through <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 from midnight tonight.
Either setInterval is not running to update the time, or the variable can only be updated if the page is reloaded?
@Nilbervittorazii never used ajax in any project. Could you give me more instructions on how to proceed? Edit: thanks, I’ll try to follow what you’ve been through.
– Wesley
@Nilbervittorazii thanks for informing what to do, really updates now. But I was completely lost on how to adapt to the project, before it was just javascript, and the rest of the function I don’t know how to include along with its.
– Wesley
@Nilbervittorazii made the issue of the question including all the code I’m using, could you instruct me again? thanks in advance.
– Wesley
The variable "N" is being used where in your javascript? I didn’t see anything referencing it.... " var n = <?php"... explain what you want to do at the end of all this...
– Nilber Vittorazzi
Sorry, I forgot to change the code when I passed here to the question, the "N" is in "c = (( N - secondsInicio + duraYujia ) % duraYujia ) / duraYujia;" and represents the second current so that the "pin" moves on the map according to the server time.
– Wesley
updated again, remembering that the code is not complete, I just joined where should be my part along with your..
– Nilber Vittorazzi
Thank you, it worked perfectly. Parseint is used to join the two functions?
– Wesley
parseint is only to ensure that if the result of PHP comes as text it converts to integer, for vc can use as number in its javascript function
– Nilber Vittorazzi