Seconds vs milliseconds vs nanoseconds: which unit is a timestamp in?

Seconds, milliseconds, microseconds and nanoseconds are the four units a Unix timestamp is written in, and each step between them is a factor of 1,000. The choice trades range for precision: a 64-bit second count lasts for billions of years, while a 64-bit nanosecond count runs out in 2262 and does not fit in a JavaScript number at all. Paste a value below to see which unit it is in.

The four units and how to spot them

Unix time is a count from 1970-01-01T00:00:00Z. Count seconds and a current value has 10 digits: 1700000000. Count milliseconds and it has 13: 1700000000123. Microseconds give 16 digits and nanoseconds 19: 1700000000123456789. All four describe the same instant, 14 November 2023 at 22:13:20 UTC, plus a fraction that each unit holds more of.

The length of the integer is the quickest tell. A decimal point is the second clue: 1700000000.123 is seconds with a fraction, which is what Python's time.time() returns, while 1700000000123 with no point is milliseconds. The Unix timestamp converter reads the unit from the number of digits and names it above the result.

Range versus precision

A signed 64-bit integer tops out at 9223372036854775807. Counting seconds, that is about 292 billion years. Counting nanoseconds, the same integer runs out on 2262-04-11T23:47:16Z, which is why Go's time.UnixNano and several databases document that date as their ceiling.

JavaScript has a tighter limit. Its numbers are 64-bit floats, exact only up to 2^53, which is 9007199254740991. Every millisecond timestamp fits, since the Date type itself stops at 8640000000000000. A microsecond count stays exact until the year 2255. A nanosecond count for any date after April 1970 is already past 2^53, so Number("1700000000123456789") rounds to the nearest double, which prints as 1700000000123456800. The last digits are gone before your code runs.

Where each unit shows up

Seconds are the Unix default: the C time_t, the shell's date +%s, Python's time.time(), JWT exp claims and most REST APIs. Milliseconds are the JavaScript and Java default through Date.now() and System.currentTimeMillis(), and Kafka stamps every record in milliseconds. Microseconds appear in PostgreSQL, whose timestamp type keeps six fractional digits, and in Python's datetime, which also stops there. Nanoseconds are the Go default with time.UnixNano, the resolution of Linux's clock_gettime and of ext4 file timestamps, and the unit InfluxDB uses on the wire.

Prometheus is the odd one: it stores millisecond timestamps, but its query language returns time as seconds in a float. When two systems meet, check the unit before you check anything else.

Converting without losing digits

Divide or multiply by 1,000 per step, and do it on integers. In JavaScript, use BigInt for anything finer than milliseconds: BigInt("1700000000123456789") / 1000000n is 1700000000123n, and the % operator keeps the 456789 you dropped. If the value arrives as a string, slice it instead of parsing it. The first 10 characters are the seconds and the first 13 are the milliseconds, with no arithmetic and no rounding. In Python, integers are unbounded, so 1700000000123456789 // 10**9 is safe. Go's time.Unix(sec, nsec) takes seconds and nanoseconds as two int64 values.

parsetime slices the string the same way. A 19-digit input is shown to the millisecond, and a note says the last six digits were dropped. For a 13-digit value, the milliseconds to date page shows the seconds form next to it.

Try it with the converter

Shown to the millisecond; the last 6 digits of the input were dropped.

Detected: Unix timestamp (nanoseconds)/t/1700000000123456789

Your timezone

UTC · GMT+00:00 · UTC

Tue, Nov 14, 2023, 10:13:20.123 PM

Common formats

UTC

Tue, Nov 14, 2023, 10:13:20.123 PM

ISO 8601

2023-11-14T22:13:20.123Z

Unix (seconds)

1700000000

Unix (millis)

1700000000123

Unix (nanos)

1700000000123456789

Relative

…

Common questions

How do I tell if a timestamp is in seconds or milliseconds?
Count the digits. A current value is 10 digits in seconds and 13 in milliseconds; 16 is microseconds and 19 is nanoseconds.
Can JavaScript handle a nanosecond timestamp?
Not as a number. Values above 2^53 lose precision, so keep nanosecond timestamps as strings or BigInt and convert to milliseconds before creating a Date.
When does a nanosecond timestamp overflow?
A signed 64-bit nanosecond count overflows on 2262-04-11T23:47:16Z. Seconds and milliseconds in 64 bits last millions of years longer.
Which unit should I store?
The one your source clock gives you, with the unit in the field name, such as created_ms. Converting on the way in is where digits get lost.

Related pages