Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is epoch time the same on the same machine with diffent scripts/programs

I want to use shell to get epoch time and later use javascript on a html page to get another epoch time and then get the difference between them but I'm afraid that the epoch time may not be synchronized among different scripts so this difference is useless

so I want to know, if at the very same time, I use shell and javascript to get epoch tiem will the result be the same or not? if not, how big is the difference?

thanks!

like image 498
user1769686 Avatar asked Nov 12 '22 18:11

user1769686


1 Answers

If you mean number of seconds since Unix epoch (1970-01-01T00:00:00Z), it is governed by this very definition. The only differences you should be able to see are caused by:

  • different times of invocation of the system call that returns it*);
  • unsynchronized clocks on different systems.

and possibly also:

  • unsynchronized clocks on different processor cores/physical processors;
  • implementation dependent handling of the function that returns current time (e.g. JS engine implementation might possibly cache the value for a short time as not to have to do the actual syscall, although I would doubt this).

Depending on the time resolution you need, some of these are not a problem. My guess is, that if you don't need granularity finer than 1s, you should be more than fine (on the same machine).

*) also note, that on single core system, you can't really get the same time (at least with the ns resolution) from different syscalls, unless the kernel caches it, simply because they have to happen one after another.

like image 187
peterph Avatar answered Nov 15 '22 07:11

peterph