Get time elapsed - Get timestamp

07/05/2020

Get time elapsed

const hrstart = process.hrtime();

setTimeout(function() {
    const hrend = process.hrtime(hrstart);

    const s = hrend[0] + hrend[1] / 1000000000;
    console.log(`waited ${s} s`);

    const ms = hrend[0] * 1000 + hrend[1] / 1000000;
    console.log(`waited ${ms} ms`);

    const µs = hrend[0] * 1000000 + hrend[1] / 1000;
    console.log(`waited ${µs} µs`);

    const ns = hrend[0] * 1000000000 + hrend[1];
    console.log(`waited ${ns} ns`);
}, 1000);

get timestamp unix (seconds)

console.log(ParseInt(Date.now() / 1000));

get timestamp milliseconds

console.log(Date.now());

get timestamp microseconds

console.log(Date.now()*1000);

get timestamp nanoseconds

console.log(Date.now()*1000000);

Raccourcis