Epoch time with 18 digits

Trying to generate epoch time at the nanoseconds so that it is 18 digits.
There are some suggestions out there on the web with node.js using process.hrtime()
Any suggestions to make this work and get the current time at the nanoseconds

thanks

Hi @mark.sadegursky!

I tried my best but looks like we need process.hrtime() in order to make it work.
However, process module is not available as discussed here :frowning_face:

If this module was available, it would be possible to utilise one of external libraries such as this one to make it work by leveraging eval() function, e.g.

In pre-request:

pm.sendRequest('https://peterolson.github.io/BigInteger.js/BigInteger.min.js', (err, res) => {
    if (err) {
        console.log(err)
    } else {
        pm.environment.set('bigInt', res.text())
    }
})

In test script:

eval(pm.environment.get('bigInt'))
//const loadNs = process.hrtime();
const loadMs = new Date().getTime();
const diffNs = [ 8, 886896255 ] // should really be process.hrtime(loadNs)
const value = bigInt(loadMs).times(1e6).add(bigInt(diffNs[0]).times(1e9).plus(diffNs[1])).toString();
console.log(value)

I hope you find this helpful a bit :slightly_smiling_face:

1 Like

Amazing thanks this is exactly what I needed.

Glad to hear that it was helpful :smiling_face_with_three_hearts: