Browsers typically provide time values in milliseconds. The DOMHighResTimeStamp was intended to provide accuracy to microsecond and while some browsers toyed with it, I don't think any currently provide that level of accuracy.
The timestamp in the OP is to nanosecond level, that's one millionth of a millisecond. I don't think browsers or other implementations will be at that level of precision for some time and the resulting time value is beyond the range of values that ECMAScript numbers can safely represent. Any numbers after the 3rd decimal place are just noise and will be mostly nines (9s) and zeros (0s).
Anyway, in theory you can get a the current millisecond value from toISOString, then update it with values from the performance object to get whatever precision it provides, e.g.
// Current time in seconds precise to ±5 microseconds with
// nanosecond precision
function getSeconds() {
return ((performance.timing.navigationStart + performance.now()) / 1000).toFixed(9);
}
// Get timestamp to nanosecond precision
function getTimestamp() {
let s = getSeconds();
// Create a Date from the time value as milliseconds
let d = new Date(s * 1000);
// Tack on the decimal seconds from the time value
return d.toISOString().replace('T',' ').replace(/\d\d(\.\d+)?Z$/, (s%60).toFixed(9) + ' Z');
}
console.log(getTimestamp());
The nanosecond precision is not nanosecond accuracy if only because of the function call, which likely takes a couple of nanoseconds itself (and the previously mentioned inability of ECMAScript to represent the required number of significant digits). Plus the system clock is extremely unlikely to be that accurate, so you might as well just tack on 6 zeros to the decimal part of the seconds from toISOString:
console.log(new Date().toISOString().replace('T', ' ').replace('Z', '000000 Z'));
and not pretend to be more accurate than reasonable. That may change when systems start to support more accurate high precision time values and BigInt is available to preserve the decimal milliseconds (though there will still be the issue with accuracy).