-2

Hey I noticed something weird while developing an app that is supposed to run synchronized to a server.

JavaScript's unix timestamp is different on each device! :O
The experiment: I open the chrome dev console and did 2 commands:

new Date()

And

new Date().getTime()

Both of the commands are executed at the EXACT same time (I pressed enter on both computers at the very exact same time)

The output was as follows:

Computer 1:
enter image description here

Computer 2
enter image description here

It is highly likely that this problem occurs due to one computer being Central Europe Standard Time and the other W. Europe Standard Time, but I can't ask all my clients to just go to Central Europe standard time.

Is there a way to get the same unix timestamp on both devices regardless of their clock if both are called at the exact same time?

ErikBrandsma
  • 1,661
  • 2
  • 20
  • 46
  • I think that only way to make sure you have the same timestamp on different clients is to get it from the same remote source (web service or similar) – Vedran Jukic Nov 22 '16 at 22:01
  • It's only off by about 16 seconds, I doubt time zones are to blame. Maybe one machine's clock is off? – Alexander O'Mara Nov 22 '16 at 22:13

1 Answers1

2

Both computers probably have a different time, did the user set it up manually? you can use a web service, see Free Rest API to get current time as string (timezone irrelevant)

Community
  • 1
  • 1
nottu
  • 369
  • 1
  • 12
  • Yes that is right, I was just wondering if I could get a unified timestamp for the purpose of measuring the time it took for an internet request to reach the server – ErikBrandsma Nov 22 '16 at 22:08
  • @ErikBrandsma if the answer solved your problem then consider marking it as accepted answer – ramazan polat Nov 22 '16 at 22:32