Timestamp guide
Unix timestamp seconds vs milliseconds
The same date can be written as Unix seconds or Unix milliseconds. Mixing the two is one of the fastest ways to get a date that looks wildly wrong.
Why the date looks wrong
Current Unix timestamps in seconds are usually 10 digits. Current Unix timestamps in milliseconds are usually 13 digits. If you convert one as the other, the result lands in the wrong year.
Example
1715200000
1715200000000
1715200000 is seconds. 1715200000000 is milliseconds.
How to choose the right unit
- Count the digits before converting the timestamp.
- Use seconds for 10-digit current timestamps and milliseconds for 13-digit current timestamps.
- If the converted date looks far in the past or future, switch units and check again.
A quick digit check
For current dates, 10 digits usually points to seconds and 13 digits usually points to milliseconds. It is not a formal rule for every historic or future value, but it catches most everyday debugging mistakes.
When a converted date lands in 1970 or far in the future, switch the unit before looking for a deeper bug.
Common mistakes
- Sending milliseconds to an API field that expects seconds
- Storing seconds in a database column named milliseconds
- Comparing timestamps from two systems without checking units
- Reading JavaScript Date.now() as seconds
Related problems
FAQ
What unit does JavaScript Date.now() return?
Date.now() returns milliseconds since January 1, 1970 UTC.
Are database timestamps always seconds?
No. Databases and APIs vary. Check the field name, docs, and digit count.
Why is my timestamp date in 1970?
You may have treated a small seconds value as milliseconds, or the value may be a short duration rather than an absolute timestamp.