epochdesk

EPOCHDESK / GUIDES

Seconds vs milliseconds vs microseconds: timestamp conversion

Seconds, milliseconds and microseconds can describe the same instant. The difference is their scale: one second contains 1,000 milliseconds or 1,000,000 microseconds.

The same instant in three units

These values all represent 2024-01-01T00:00:00Z:

UnitValueUnits per second
Seconds17040672001
Milliseconds17040672000001,000
Microseconds17040672000000001,000,000

Conversion formulas

For example, 1704067200123456 microseconds is 1704067200.123456 seconds. Epochdesk displays the full instant as 2024-01-01T00:00:00.123456Z; its integer seconds and milliseconds outputs are rounded down.

Can I identify the unit by length?

Contemporary values commonly have 10 digits for seconds, 13 for milliseconds and 16 for microseconds. Epochdesk auto mode uses at most 10 digits for seconds, at most 13 for milliseconds, and longer values for microseconds. It ignores the sign and leading zeros when counting integer digits. This is a heuristic: the number 1000 could mean 1,000 seconds or just one second in milliseconds. Your API documentation is the better source.

JavaScript examples

const milliseconds = Date.now();
const seconds = Math.floor(milliseconds / 1000);
const iso = new Date(1704067200000).toISOString();
// 2024-01-01T00:00:00.000Z

JavaScript Date expects milliseconds. It cannot preserve microseconds in its internal time value. Keep precise source values as strings or use BigInt integer arithmetic; converting large integers through Number can lose digits. Epochdesk uses BigInt for its timestamp arithmetic.

Choose the unit before interpreting the result

Use the converter to compare all three outputs. If a date looks decades away from the expected event, first check the unit. Nanoseconds are not supported: convert them deliberately and decide how to handle the discarded precision.

Practical timestamp guides