Server Date.now()

Hello guys, I have a problem. On server, Date.now() does not match Date.now() on client side even at the same time, there is like 1500 (and its not always the same difference - 1500, sometimes 1400 and sometimes 1600 etc) milliseconds difference, why is it like this? I need to have it matched to do precious calculations with socket.io. Dont you know how to solve this?

Hey @iHux3, welcome to the Glitch forum!

I’m not sure what socket.io calculations you’re trying to do, but I don’t think you can count on server time and client time being in sync. Your project is running inside a container that’s running on a virtual server that’s running on a physical server in an Amazon data farm somewhere in the eastern US and there may be slight variations on any one of those layers, not to mention between your project and any possible client. All those differences will likely add up to larger clock drift like you’re seeing.

Add to that the fact that your project may change to a different host as often as every 12 hours (conceivably more of it goes to sleep) and I think you’re fighting a losing battle.

If you let us know what you’re trying to accomplish someone might be able to offer some alternatives, but I think that’s as good as you’re going to get.

Thanks for your response, I am making a multiplayer shooter game with socket.io, there is around 130ms delay in my country. I want to do lag compensation, for example when a player shoots, he sees his enemy in past because of the 130ms delay, so i need to send the timestamp when the player shoots and then on server side calculate the delay between shooting and receiving, so the server can calculate the position of the enemy position in past in view of the player before, so the player can hit the enemy, but thats not possible if the server time cannot be in sync with a client.

Thanks for the additional info, @iHux3! Makes sense that you would need pretty accurate times for what you’re trying to do.

Currently the Glitch project containers don’t time sync at all, and I’m not sure that it’s something we’re likely to add to the container, but I definitely encourage you to add a topic in https://support.glitch.com/c/feature-ideas to help us gauge interest (don’t forget to vote for it yourself, if you do so).