Milliseconds to Seconds
Convert integer milliseconds into exact seconds, whole seconds rounded down, and the remaining milliseconds. Negative timestamps and durations work too; the calculation preserves integers beyond JavaScript’s safe-number range.
Milliseconds to seconds
Enter a value to see results below. Enter a signed integer, up to 30 digits. Works for durations and epoch timestamps.
Exact seconds preserve the fraction. Whole seconds round toward negative infinity: −1 ms = −0.001 s, or −1 whole second + 999 ms. “Now” uses your device clock.
13 digits vs 10 digits
| Value | Digits | Unit | Whole seconds (floor) |
|---|---|---|---|
1712345678 | 10 | seconds | 1712345678 |
1712345678901 | 13 | milliseconds | 1712345678 |
1712345678901234 | 16 | microseconds | 1712345678 |
1712345678901234567 | 19 | nanoseconds | 1712345678 |
Typical millisecond sources are JavaScript Date.now(), Java System.currentTimeMillis() and Python time.time_ns() // 1_000_000; today these have 13 digits. POSIX time() returns seconds, currently 10 digits. Database columns and API fields can use either unit: check their schema rather than assuming from the name or storage type.
Why Math.floor and not Math.round
Converting ms→s with rounding (Math.round(ms / 1000)) makes the seconds value jump one tick early: for positive values, milliseconds ...500 through ...999 within a second round up into the next second, so two events inside the same second can display as consecutive seconds. Worse, round-tripping (multiply by 1000 back) invents timestamps that never existed.
- Floor going down:
Math.floor(ms / 1000)in JS,ms // 1000in Python,Math.floorDiv(ms, 1000L)in Java. Go integer division truncates toward zero: uses := ms / 1000; if ms % 1000 < 0 { s-- }for floor. Negative values expose the difference: -1 ms belongs to second -1, not 0. - Multiply going up:
s * 1000gives the start of that second. If you need the end, uses * 1000 + 999. - Compare in one unit. Half your pipeline in seconds and half in ms is where "off by a thousand times" bugs live; convert at the boundary and keep internals in a single unit.
ANSWERS
01 Is 1712345678901 in milliseconds or seconds?
For a contemporary date, milliseconds is the plausible interpretation: 2024-04-05 19:34:38.901 UTC. Read as seconds, it lands in year 56232. Digit count is a useful hint, but only the source schema establishes the unit.
02 What is 1000 milliseconds in seconds?
1 second exactly. Unix time counting is decimal, so all unit steps are factors of 1,000: ms→s, µs→ms, ns→µs. (FILETIME, by contrast, counts 100-nanosecond ticks — 10,000,000 ticks per second.)
03 Why are my two conversions off by one second?
Usually Math.round somewhere in one of the two code paths: positive second values with fractions .500–.999 round up to the next second while the other path floors. Standardize on floor for ms→s and the discrepancy disappears.
04 How do I go back from seconds to milliseconds?
Multiply by 1,000. In JavaScript watch out for very large epoch values: numbers above 2^53 lose integer precision, which only matters for far-future timestamps or when you multiply a 19-digit nanosecond value — use BigInt there.
05 Which unit does the Unix standard actually define?
Seconds. POSIX defines the time as seconds since the Epoch, and time_t is a seconds counter. Milliseconds and below are extensions adopted per-language (JS Date, Java Instant, Go Time) — which is why the same event has four legitimate representations and why converters must detect the unit.