This question already has an answer here:
I want to know if it is possible to get the serverTime (in a variable that can be used later on in javascript) with jquery ajax functions as $.get() or $.post().
The link of the webpafe is :http://zz1.beta.tribalwars.net/game.php?village=1466&screen=overview
I think that for get and post functions you need to use the url: "game.php" This is a printscreen of the webpage: http://prntscr.com/4npk47
I could do something like that :
var time=document.getElementById('serverTime');
but with this method, after a while, if the webpage is not reloaded, the time is desynchronized with about 1-2 seconds, and i need the exact time.
</div>
var serverTime = time ; //this would come from the server obviously
var localTime = +Date.now();
var timeDiff = serverTime - localTime;
setInterval(function () {
console.log(+Date.now() + timeDiff);
}, 1000);
You could use a Node.js on the backend with socket.io, using websockets, and stream the real-time (see how I did that!?). Then your client side JS would connect to the websocket and just stream the time out from the server.