Date.now() on server in advance relative to client?

Here is my situation:

I have a client connected to a server with Node.js, socket.io.

If I calculate Date.now() on server, send it to the client, and then make the client print the time received from the server and it's own Date.now() I get a very strange result: The server time is 514ms bigger than the client time. But logically the server Date.now() has to happen before the client-one.

I don't understand what is happening here. Does the server calculate Date.now() differently than the client because of its time zone ? Is something else happening ?

What you're seeing is called clock skew. Like any clock, the clock inside a computer has to be set to the correct time, and the clocks for any two computers slowly diverge from one another. Therefore, it's almost certain that any two computers will think its a slightly different time. Usually, this difference is small enough that you don't notice, but it can be big enough to see it when you deliberately run an experiment like the one you just did.