CLOCK_MONOTONIC
is from arbitrary epoch, and it actually varies from machine to machine and every boot in Linux. You should use it only to measure intervals, i. e.
(int64_t)(after.tv_sec - before.tv_sec) * (int64_t)1000000000UL
+ (int64_t)(after.tv_nsec - before.tv_nsec)
. For timestamps, use CLOCK_REALTIME
, as it uses the 1970-01-01 00:00:00 UTC epoch. int64_t
can handle CLOCK_REALTIME
timestamps at nanosecond precision –
(int64_t)(t.tv_sec) * (int64_t)1000000000 + (int64_t)(t.tv_nsec)
–, dates from year 1679 to 2261 at least; the range is ±292 years, not ±145 years.
– Nominal Animal