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:
| Unit | Value | Units per second |
|---|---|---|
| Seconds | 1704067200 | 1 |
| Milliseconds | 1704067200000 | 1,000 |
| Microseconds | 1704067200000000 | 1,000,000 |
Conversion formulas
- Seconds × 1,000 = milliseconds.
- Milliseconds × 1,000 = microseconds.
- Microseconds ÷ 1,000,000 = seconds, including any fraction.
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.000ZJavaScript 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.