12
I need to adapt my code to calculate the difference between the server time where the site is hosted and the user’s computer time so as not to overload my system.
I am mounting a table where I will show the time of another server and need to update every second.
So I have to get three dice:
- Time of the server where the site is hosted
- Device time that is accessing the site to know the difference between server time
- Difference of the third server that will be recalculated every second
The third item I have set in Javascript as follows:
<script>
var difJogo = (-145);
</script>
Means the game server is 145 seconds behind the site server (main reference).
To get the time of the site’s server I use:
<?php
date_default_timezone_set('America/Sao_Paulo');
$cH = date('G');
$cM = date('i');
$cS = date('s');
echo $cH .':'. $cM .':'. $cS;
?>
And to get user device time use:
<script>
function hat() {
var sAg = ( Date.now() / 1000 ) % 86400;
}
</script>
What I can’t do is unite all these functions to get where I want. The time of the site server needs to be the basis of everything because there are people who access the site from different places in the world, so I want to define that the time is the same for everyone using São Paulo time zone.
The final logic is: Horário do servidor - Horário do dispositivo + Diferença do Jogo.
This requires a function to display the game server time and update every 1 second.
looks like q vc is using php serverside and js clientside. Do you want the data in the client or server? either way I would do an endpoint on the server that receives the client date, or that returns the server date pro client, depending on where Voce wants to use the end value
– guijob