formatting

Date.prototype.toISOString

Returns the date as an ISO 8601 extended-format string in UTC, always ending in 'Z'. This is the canonical machine-readable serialization and the format most APIs and databases accept.

date.toISOString()

Parameters

Parameter Purpose
() no arguments; returns 'YYYY-MM-DDTHH:mm:ss.sssZ'
UTC always UTC regardless of host timezone
Invalid Date throws RangeError

Examples

console.log(new Date(0).toISOString()); // '1970-01-01T00:00:00.000Z'

epoch

console.log(new Date('2026-07-19T12:34:56.789Z').toISOString()); // '2026-07-19T12:34:56.789Z'

round-trip

try { new Date('bad').toISOString(); } catch (e) { console.log(e.name); } // 'RangeError'

throws on invalid

Gotcha

Always UTC (Z suffix) - it does NOT show local time. Throws RangeError on Invalid Date, unlike most other formatters which return 'Invalid Date' as a string.

Related

← All JS Date methods · Math methods · Cron syntax