What time are the process.hrtime() and process.hrtime.bigint() functions referring to in Node.js?

Viewed 3562

the process.hrtime() is a legacy version of process.hrtime.bigint() method

process.hrtime();                     // -> [27511, 516453000]   (seconds, remaining nanoseconds)
process.hrtime.bigint();              // -> 27511516453000n      (nanoseconds)
  • 27511516453000 nanoseconds are 7.6420879036111113 hours

    When I'm Testing this the time is 11:54 UTC and 14:54 Locale Time

  • the 7.64 hours does not refer to the current time so what is that 7.64 hours are referring to?
1 Answers

The meaning of these values is defined in the documentation (although it's easy to miss, since it's just one line):

These times are relative to an arbitrary time in the past, and not related to the time of day and therefore not subject to clock drift.

So in other words, hrtime is only useful for calculating the time relative to another point in time. If you call hrtime now, and then again ten seconds in the future, the result of subtracting the former from the latter will equal ten seconds. The values returned by those two calls, however, have no real meaning in isolation from each other.

Related