Home → Unix Timestamp: Seconds vs Milliseconds
Unix Timestamp: Seconds vs Milliseconds
The difference between Unix seconds and Unix milliseconds is simple mathematically but responsible for many real-world timestamp bugs. Both represent the same kind of instant, but one second contains 1,000 milliseconds.
| Unit | Multiplier from seconds | Common example |
|---|---|---|
| Seconds | 1 | 1767225600 |
| Milliseconds | 1,000 | 1767225600000 |
How to convert
Seconds to milliseconds: multiply by 1,000. Milliseconds to seconds: divide by 1,000. If the target system expects whole seconds, decide whether to floor, round or reject fractional values rather than silently losing precision.
seconds = milliseconds / 1000
Where each unit appears
- JavaScript:
Date.now()returns milliseconds. - Unix-like APIs: whole seconds are common.
- Databases: schemas differ, so check the column type and application code.
- Logs: systems may store either, or even another precision such as microseconds.
Do not guess only from digit count
A 10-digit number often looks like Unix seconds today, and a 13-digit number often looks like Unix milliseconds. But older or future dates can have different lengths, and custom data can be formatted differently. Documentation is the reliable source of truth.
Debugging a 1,000× error
If a converted date is thousands of times too far into the past or future, check the unit first. Normalizing both values to milliseconds or both to seconds before comparison usually reveals the issue quickly.
Related Timestamp Tools
Choosing Seconds or Milliseconds in Real Applications
Seconds and milliseconds are both common timestamp units, but mixing them is one of the easiest ways to create a date that looks absurdly wrong. A good system treats the unit as part of the data contract. If a database column, API field, or event stream says 'Unix milliseconds', every consumer should interpret it in that same unit until an explicit conversion is made.
A safe conversion rule
To convert whole Unix seconds to milliseconds, multiply by 1,000. To convert milliseconds to Unix seconds, divide by 1,000, deciding what to do with any fractional remainder. Do not repeatedly convert the same value as it passes through multiple services; keep one canonical unit at the boundary and adapt only for libraries that require another representation.
Quick reference
| Unit | Scale | Common examples |
| Seconds | 1,000 ms | Unix/POSIX timestamps, many APIs |
| Milliseconds | 1 ms | JavaScript Date, browser timestamps |
| Microseconds | 0.001 ms | High-precision event data |
| Nanoseconds | 0.000001 ms | Some telemetry and systems code |
Practical checks
- Name timestamp fields with the unit when possible, such as created_at_ms.
- Check language defaults before passing values to date constructors.
- Preserve precision until the final presentation layer.
- Write a small unit test that converts a known timestamp in both directions.
Frequently Asked Questions: Practical Details
Why do JavaScript and Unix examples often use different digit lengths?
JavaScript commonly uses milliseconds while traditional Unix examples often use seconds.
Should I always convert everything to milliseconds?
No. Use the unit defined by the system boundary and convert only when the target library needs a different unit.
What is the fastest way to spot a unit bug?
Compare the value with a known recent date and check whether it differs by roughly 1,000× from the expected representation.
Frequently Asked Questions
How many milliseconds are in one second?
Exactly 1,000 milliseconds.
Does JavaScript use seconds or milliseconds?
The JavaScript Date constructor and Date.now() commonly use milliseconds since the Unix Epoch.
Why does my timestamp produce a wildly wrong date?
A seconds/milliseconds mismatch is one of the most common causes.