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.

[SEC.01 // UNITS]

Milliseconds to seconds

EXACT INTEGER INPUT

Enter a value to see results below. Enter a signed integer, up to 30 digits. Works for durations and epoch timestamps.

Exact seconds —
Whole seconds (floor) —
Remaining milliseconds —
Microseconds —
Nanoseconds —

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.

[SEC.02 // QUICK TABLE]

13 digits vs 10 digits

SPEED CHECK
ValueDigitsUnitWhole seconds (floor)
171234567810seconds1712345678
171234567890113milliseconds1712345678
171234567890123416microseconds1712345678
171234567890123456719nanoseconds1712345678

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.

[SEC.03 // FLOOR VS ROUND]

Why Math.floor and not Math.round

JUMPING SECONDS

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 // 1000 in Python, Math.floorDiv(ms, 1000L) in Java. Go integer division truncates toward zero: use s := 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 * 1000 gives the start of that second. If you need the end, use s * 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.
[DOC.FAQ // INDEX]

ANSWERS

05 ITEMS
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.

[SEC.MATRIX // RELATED]

Related tools

3 PAGES

Sources and specifications