# Epoch time with 18 digits

**URL:** <https://community.postman.com/t/epoch-time-with-18-digits/19672>\
**Category:** Help Hub\
**Tags:** pre-request\
**Created:** [January 28, 2021, 11:21pm UTC](https://community.postman.com/t/epoch-time-with-18-digits/19672 "2021-01-28T23:21:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark.sadegursky](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/mark.sadegursky/32/223_2.png) [@mark.sadegursky](https://community.postman.com/u/mark.sadegursky)\
**Post date:** [January 28, 2021, 11:21pm UTC](https://community.postman.com/t/epoch-time-with-18-digits/19672/1 "2021-01-28T23:21:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [January 29, 2021, 6:22am UTC](https://community.postman.com/t/epoch-time-with-18-digits/19672/2 "2021-01-29T06:22:33Z")

</div>

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](https://community.postman.com/t/error-cannot-find-module-process-in-pre-request-script-when-calling-process-cwd/341) ☹

If this module was available, it would be possible to utilise one of external libraries such as [this one](https://github.com/sazze/node-nanotime/blob/master/index.js) 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 🙂

---

<div class="post-metadata">

**Author:** ![mark.sadegursky](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/mark.sadegursky/32/223_2.png) [@mark.sadegursky](https://community.postman.com/u/mark.sadegursky)\
**Post date:** [January 29, 2021, 1:13pm UTC](https://community.postman.com/t/epoch-time-with-18-digits/19672/3 "2021-01-29T13:13:34Z")

</div>

Amazing thanks this is exactly what I needed.

---

<div class="post-metadata">

**Author:** ![taehoshino](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/taehoshino/32/6608_2.png) [@taehoshino](https://community.postman.com/u/taehoshino)\
**Post date:** [February 3, 2021, 3:08am UTC](https://community.postman.com/t/epoch-time-with-18-digits/19672/4 "2021-02-03T03:08:39Z")

</div>

Glad to hear that it was helpful 🥰
