How to get nano seconds from milisecond since epoch?

3.7k Views Asked by At
    const time = '2022-01-13T18:40:44.748903Z';
    const date = new Date(time);
    const millisecondsSinceEpoch = date.getTime();
    const seconds = Math.floor(millisecondsSinceEpoch / 1000);

how to get nano seconds in Javascript?

1

There are 1 best solutions below

0
Kech - agmaio On

Multiply the millisecondsSinceEpoch variable by 1000000 for the nanosecond conversion, this is because a nanosecond is 1000000 times smaller than a millisecond.

var nanosecondsSinceEpoch = millisecondsSinceEpoch * 1000000;