Reputation: 865
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
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