icelemon
icelemon

Reputation: 865

How to get nano seconds from milisecond since epoch?

    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?

Upvotes: 0

Views: 4752

Answers (1)

Kech - agmaio
Kech - agmaio

Reputation: 41

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;

Upvotes: 3

Related Questions