Unix timestamp converter, down to the nanosecond
Paste an epoch timestamp in any unit — the unit is detected from its length — or a date, and get it back in every unit at once. Nanoseconds survive the round trip, so OpenTelemetry's timeUnixNano values convert exactly.
Which unit is my timestamp in?
Count the digits. A Unix timestamp for any date between 2001 and 2286 has 10 digits in seconds, 13 in milliseconds, 16 in microseconds and 19 in nanoseconds. The converter uses the same rule — up to 11 digits is seconds, 12–14 milliseconds, 15–17 microseconds, anything longer nanoseconds — and you can override it with the unit picker when a value is ambiguous.
| Unit | Digits today | Where you meet it |
|---|---|---|
| Seconds | 10 | date +%s, PHP time(), Python int(time.time()), JWT exp |
| Milliseconds | 13 | JavaScript Date.now(), Java System.currentTimeMillis() |
| Microseconds | 16 | PostgreSQL internals, Python time.time_ns() // 1000 |
| Nanoseconds | 19 | OpenTelemetry timeUnixNano, Go UnixNano(), date +%s%N |
Nanoseconds in OpenTelemetry
OTLP carries every time as fixed64 nanoseconds since the epoch — timeUnixNano
on a log record, startTimeUnixNano and endTimeUnixNano on a span. In OTLP/JSON
the value is written as a string, because a 19-digit integer does not fit in a JavaScript
number: 1760020200123456789 parsed as a double comes back as 1760020200123456800.
This converter never passes the value through a float, so the last digits survive. The field is
unsigned, so dates before 1970 cannot be expressed, and the largest value a signed 64-bit integer holds
is 2262-04-11.
Storing them
ClickHouse keeps nanosecond time in DateTime64(9), which is what the OpenTelemetry
exporter's tables use and what Bilis stores logs, spans and metrics
in. The literal on the last line above can be pasted straight into a query's WHERE.
More free tools
- Log volume & cost calculator Events per second to GB a day, a per-GB SaaS bill, and the disk the same logs need on your own box.
- Log levels, mapped Syslog, PSR-3, Python, Log4j, slog, pino, .NET and Ruby levels side by side, on the OpenTelemetry severity scale.
- Traceparent decoder Decode, validate or generate a W3C Trace Context traceparent header.
These tools are made by Bilis: self-hosted logs, traces and metrics that you and your coding agent read alike, stored on your own box in OpenTelemetry's formats. See what it does or read the docs.