Unix Timestamp Seconds vs Milliseconds
Learn how Unix seconds, Unix milliseconds, ISO strings, UTC, and local time relate during API and log debugging.
The two timestamp lengths you see most often
Unix timestamps count time since January 1, 1970 UTC. The confusing part is that different systems use different units. Many APIs use seconds, while JavaScript Date values commonly use milliseconds.
A 10-digit timestamp is usually Unix seconds. A 13-digit timestamp is usually Unix milliseconds. Treat that as a useful clue, not a guarantee, because old dates, far-future dates, and custom systems can look different.
Why seconds and milliseconds get mixed up
JavaScript Date expects milliseconds in many places, but JWT exp and iat claims use seconds. Databases, logs, queues, and APIs may choose either format. Passing seconds into a milliseconds API can produce a date near 1970. Passing milliseconds into a seconds field can create a date thousands of years in the future.
When debugging, convert both ways and check whether the readable date makes sense for the event you are investigating.
- Unix seconds example: 1717588800
- Unix milliseconds example: 1717588800000
- ISO example: 2024-06-05T12:00:00.000Z
UTC vs local time
Unix timestamps represent an absolute moment. Local time is how that moment appears in a specific timezone. UTC is the common reference used by servers, logs, and ISO strings.
If a job appears to run at the wrong hour, compare the UTC time, the server timezone, the user's local timezone, and any scheduler setting. The timestamp may be correct while the displayed local time is surprising.
Practical checks before shipping
Use a timestamp converter when you add test data, inspect event logs, debug JWT expiration, or compare scheduled jobs. Always note whether a field expects seconds, milliseconds, or an ISO string.
In documentation and API examples, label the unit clearly. A field named expiresAtMs is much harder to misuse than a generic field named time.
FAQ
Is Unix time always UTC?
Unix time represents an absolute moment independent of timezone. UTC is the usual readable reference for that moment.
Why does JavaScript use milliseconds?
JavaScript Date stores timestamps in milliseconds since the Unix epoch, which gives more precision than whole seconds.
How do I spot the wrong unit quickly?
Convert the value and check the year. If the result is around 1970 or far in the future, seconds and milliseconds may have been mixed up.