JavaScript timestamps

Date.now() returns milliseconds — the number-one interop bug. Divide by 1000 for Unix seconds.

[MOD.DEMO // TRY]

TRY IT — PASTE A STAMP

—

Now, in milliseconds

const nowMs = Date.now(); // 13 digits

Now, in Unix seconds

const nowS = Math.floor(Date.now() / 1000); // 10 digits

Stamp to Date

const d = new Date(ts * 1000); // seconds → ms!
const iso = d.toISOString(); // always UTC

Date back to stamp

const ts = Math.floor(d.getTime() / 1000);

Display for humans

d.toLocaleString(); // local for people
// store: ts · display: toLocaleString · wire: toISOString

THE TIMEZONE PITFALL

new Date(1712345678) without ×1000 renders January 1970 — JavaScript wants milliseconds. And toString() prints local time while toISOString() prints UTC for the same instant. Rule of thumb: store seconds, display with toLocaleString, transmit with toISOString.

[DOC.FAQ // INDEX]

ANSWERS

05 ITEMS
01 How do I get the current Unix timestamp in JavaScript?

Math.floor(Date.now()/1000) for standard 10-digit seconds. Bare Date.now() is 13-digit milliseconds — fine inside JS, wrong for Python, Go or MySQL. Floor rather than round to avoid leaking into the next second.

02 Why does new Date(ts) show 1970?

You passed seconds where JavaScript expects milliseconds. Multiply by 1000: new Date(ts*1000). A 1970 date is the tell-tale sign of the seconds-vs-milliseconds mix-up.

03 How do I format a timestamp as ISO 8601?

new Date(ts*1000).toISOString() gives 2024-04-05T11:34:38.000Z, always UTC. For human display use .toLocaleString() in the local zone. Never split .toString() output — it is locale-dependent and unparseable.

04 How do I parse an ISO string back to a stamp?

Math.floor(Date.parse(iso)/1000). Date.parse handles ISO 8601 reliably; non-ISO strings such as MM/DD/YYYY are implementation-defined — avoid them and validate with the ISO page linked below.

05 Seconds or milliseconds in APIs?

Accept both, store seconds. Detect by magnitude (at or above 1e12 means milliseconds), document the contract, and return seconds. Every non-JS backend speaks seconds, and millisecond floats risk precision loss past 2^53 in JSON.

[DOC.COMPARE]

HOW THIS COMPARES

CapabilityEpoch (this site)EpochConverter
Full JavaScript guide with ms-vs-s pitfalls YES Snippets only
Live try-it demo on the page YES NO
Intl + Temporal-era formatting patterns YES Partial
Strict ISO validation linked YES NO
Free, no account YES YES

Observed October 2026 against epochconverter.com. If anything changed, tell us and we will correct it.

KEEP EXPLORING TOOLKITS

[DOC.LINKS]

ALSO WORTH A LOOK

Independent alternatives, listed for cross-checking. Presence here is not an endorsement, and corrections are welcome.