A Unix timestamp in nanoseconds counts nanoseconds (billionths of a second) since the epoch 1970-01-01T00:00:00Z. This is the resolution returned by Go’s time.UnixNano(), by many distributed-tracing systems, and by high-frequency data pipelines. Because a present-day value is about 19 digits — well beyond what a JavaScript number can hold exactly — this converter does all arithmetic with BigInt.
How it works
The tool parses the nanosecond value as a BigInt and splits it into whole milliseconds (which Date understands) plus a nanosecond remainder within the second:
const ns = BigInt(input);
const ms = ns / 1000000n; // whole milliseconds
const remNsInSecond = ((ns % 1000000000n) + 1000000000n) % 1000000000n;
const date = new Date(Number(ms));
The Date provides the calendar date-time, and the nanosecond remainder is formatted as 9 fractional-second digits in the ISO-8601 output, so no precision is lost. To encode, the tool parses the date to milliseconds and multiplies by 1000000n.
A present-day nanosecond timestamp is about 19 digits, for example 1700000000000000000. Shorter values are in microseconds (~16), milliseconds (~13) or seconds (~10).
Tips and notes
- BigInt keeps values exact even far past
Number.MAX_SAFE_INTEGER. - Browser
Date.parseresolves only to milliseconds, so encoding a plain ISO string gives a nanosecond value ending in six zeros. - The fractional-seconds field shows the full nanosecond remainder so you can verify sub-microsecond detail.