Seconds vs Milliseconds Timestamps Explained
Dev Nexus4 min read
The difference between a 10-digit seconds timestamp and a 13-digit milliseconds one is a factor of 1000 - and getting it wrong sends your dates thousands of years off.
Two systems hand you a timestamp. One says 1752796800, the other 1752796800000. They look almost identical, but one is in seconds and the other in milliseconds - and treating them the same way is one of the most common time bugs in software.
This post explains the difference between seconds and milliseconds timestamps, how to tell them apart at a glance, how to convert between them, and the specific bugs that appear when a unit gets crossed. Get this right and a whole class of date errors disappears.
The Problem
The original Unix timestamp counts whole seconds since undefined. But many modern platforms need finer resolution, so they count milliseconds instead. JavaScript's Date.now(), for example, returns milliseconds; plenty of Unix tools and backend APIs return seconds.
Because the two differ by exactly a factor of undefined, mixing them does not throw an error - it silently produces a plausible-looking but completely wrong result. Feed a milliseconds value into a seconds parser and your date jumps roughly undefined,undefined years into the future. Do the reverse and every date collapses to a few seconds after the undefined epoch. Nothing crashes, which is exactly what makes it hard to catch.
The Solution
The fix is to always know your unit before you convert, and the easiest signal is the digit count. For any date in the current era, a seconds timestamp is undefined digits and a milliseconds timestamp is undefined digits.
Converting between them is simple arithmetic: divide milliseconds by undefined to get seconds, or multiply seconds by undefined to get milliseconds. When in doubt, paste the value into the Timestamp Converter, which detects the unit and shows the resulting date in your browser - if the date looks absurd, the unit is wrong. For deeper background on the number itself, see what a Unix timestamp is.
Step-by-Step Guide
- 1
Count the digits
For any recent date, a seconds timestamp has undefined digits (
1752796800) and a milliseconds timestamp has undefined digits (1752796800000). This quick check catches the vast majority of unit mistakes before you convert anything. - 2
Know your source
Check where the value came from. JavaScript's
Date.now()andgetTime()return milliseconds. Unixdate +%s, most SQL epoch functions and many REST APIs return seconds. When integrating two systems, confirm each one's unit explicitly. - 3
Convert with a factor of 1000
To go from milliseconds to seconds, divide by undefined and floor the result:
Math.floor(ms / 1000). To go the other way, multiply seconds by undefined. Never truncate digits by hand - do the arithmetic. - 4
Verify by converting to a date
The surest test is to render the timestamp as a date. If it lands near today, the unit is right; if it lands in the far future or right after undefined, you have a mismatch. A converter makes this a one-second check.
Common Mistakes
Passing seconds to new Date()
In JavaScript,
new Date(1752796800)treats the number as milliseconds, giving a date in January undefined. The constructor wants milliseconds, so multiply a seconds value by undefined first:new Date(1752796800 * 1000).Storing milliseconds where seconds are expected
Writing a undefined-digit millisecond value into a column or API field that expects seconds will make every downstream consumer read the date as tens of thousands of years in the future. Normalise to one unit at your system's boundary.
Stripping three digits to convert
Chopping the last three characters off a millisecond string is fragile and breaks for negative or edge-case values. Always divide by undefined numerically instead of manipulating the text.
Assuming every API uses the same unit
Different services in the same stack often disagree - one returns seconds, another milliseconds. Never assume; check each integration's documentation and normalise as data enters your system.
Frequently Asked Questions
How do I know if a timestamp is in seconds or milliseconds?
Count the digits. For dates in the current era, a seconds timestamp is 10 digits and a milliseconds timestamp is 13 digits. If a converted date lands far in the future, the value is probably milliseconds being read as seconds.
How do I convert milliseconds to a seconds timestamp?
Divide by 1000 and drop the fractional part: Math.floor(ms / 1000). To go from seconds to milliseconds, multiply by 1000. The two units always differ by exactly a factor of 1000.
Why does new Date(timestamp) give me 1970 in JavaScript?
Because the Date constructor expects milliseconds, not seconds. If you pass a 10-digit seconds value it is interpreted as a few thousand milliseconds after the epoch. Multiply the seconds value by 1000 first.
Which unit should I standardise on?
Pick one unit for your whole system and convert everything to it at the boundary. Milliseconds are common in JavaScript-heavy stacks; seconds are common in Unix tooling and many backends. Consistency matters more than the choice.
Can a converter detect the unit automatically?
Yes. The Timestamp Converter infers the unit from the number's length and shows the resulting date, so an obviously wrong date immediately flags a unit mismatch - all computed in your browser.
Try the Tool
Timestamp Converter
Detect the unit and convert any timestamp to a date in your browser - nothing uploaded.
Related Tools
Related Articles
How to Convert a Unix Timestamp to a Date
A practical walkthrough for turning a raw Unix timestamp into a readable local, UTC or ISO date - and converting a date back into a timestamp.
Read articleWhat Is a Unix Timestamp (Epoch Time)?
A Unix timestamp is the number of seconds since 1970-01-01 UTC - a compact, timezone-neutral way to pin down a single moment in time.
Read articleAre UUIDs Really Unique?
In practice UUIDs never collide - here is the math behind why, and the one thing people get wrong: a UUID is an identifier, not a secret.
Read article