Victor Zhou Victor Zhou - 1 year ago 104
Node.js Question

Javascript consistency across machines / time zones

Let's say I have a node.js server running from New York, and I have a client connected to it from California using a web brwoser. How reasonably can I expect called from the client to match called from node.js on the server to within ~50-100 ms (assuming they're called at the exact same instant)? Theoretically should always be consistent across machines and time zones since "returns the number of milliseconds elapsed since 1 January 1970 00:00:00 UTC" right?

Answer Source

No, you cannot necessarily assume that the client and server time are in sync.

One of the reasons for that is is based on the system time of the user's OS. You have no control over that, the time may be correct, may be off a little bit or even completely wrong.

You can try that yourself:



I ran twice, once with the correct time set up in Windows. Then I changed the year of my system clock to 2014 and ran again.

Never rely on the correctness of information that is under control of the user without server side validation.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download