0

From the following links, does it mean that if calling timeIntervalSince1970 in different devices at SAME TIME(theoretically), the timestamp will be the same?

Thanks!

Community
  • 1
  • 1
willSapgreen
  • 1,365
  • 2
  • 17
  • 27

1 Answers1

3

timeIntervalSince1970 is the number of seconds since 1 January 1970, GMT and therefore independent of the devices time zone, the chosen date format etc. So theoretically, if the clocks of two devices were completely in sync, the value of

[[NSDate date] timeIntervalSince1970]

would be the same at the same absolute point in time.

In practice, there will always be a difference. The device clock is never 100% correct, and a user can even disable the automatic time synchronisation and set an arbitrary time manually.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Thank you for confirming my idea, Martin! – willSapgreen Apr 05 '14 at 15:37
  • I don't understand. You say: "therefore independent of the devices time zone." Then you give the condition "if the clocks of two devices were completely in sync" If it is independent of the time zone, why/when would we need such a sync? What am I missing here? Thanks. – Murat Yasar Oct 28 '16 at 23:39
  • @MuratYasar: Because clocks are not 100% precise. Even if they are synchronized with a network time server at regular intervals, chances are that two computer clocks differ *slightly.* – Martin R Oct 29 '16 at 10:31
  • @MartinR thanks for answering. So if one device's time is set manually to a time different than the other device's time which is set automatically, will NSDate().timeIntervalSince1970 print the same number? Secondly, if a device in Canada and Turkey(both devices times are set automatically) are both printing the NSDate().timeIntervalSince1970, will they print the same number or what? – Murat Yasar Oct 30 '16 at 15:26
  • If you start up a swift repl and punch in `Date().timeIntervalSince1970`, then go to System Preferences > Date & Time and change the **time zone** manually, and finally re-run `Date().timeIntervalSince1970` you will see only a few seconds of difference (the time it took to click through the UI). By contrast, if you change the **time** manually (by unselecting "Set time and date automatically"), and re-run `Date().timeIntervalSince1970` you will see a large difference in seconds (the seconds you manually adjusted the time by) – Lou Zell Sep 27 '21 at 17:01
  • @MuratYasar so to answer your questions: "So if one device's time is set manually to a time different than the other device's time which is set automatically, will NSDate().timeIntervalSince1970 print the same number?" *No* "Secondly, if a device in Canada and Turkey(both devices times are set automatically) are both printing the NSDate().timeIntervalSince1970, will they print the same number or what?" *They will be very close, but not identical due to the synchronization differences that Martin mentioned (e.g. the clocks are synchronized off a network at different times)* – Lou Zell Sep 27 '21 at 17:07