npm.io
1.0.1 • Published 1 month ago

@ljharb/now

Licence
MIT
Version
1.0.1
Deps
3
Size
12 kB
Vulns
0
Weekly
0

@ljharb/now Version Badge

github actions coverage License Downloads

npm badge

The current time, in milliseconds, from the most precise monotonic clock available - performance.now(), then process.hrtime(), then Date.now(), then new Date().getTime() (for ES3). Works in browsers and node, all the way back to ES3.

The returned value has an arbitrary origin and is only meaningful relative to another call: subtract two readings to get an elapsed duration, in milliseconds. Where the platform provides a monotonic clock (the first two tiers), it is unaffected by system clock changes.

Usage / Example

var now = require('@ljharb/now');
var assert = require('assert');

assert.equal(typeof now(), 'number');

var start = now();
// ... do some work ...
var elapsed = now() - start;

assert.equal(typeof elapsed, 'number');
assert.ok(elapsed >= 0);

Keywords