The JavaScript date.toISOString() method
The toISOString() method formats a Date as a standard ISO 8601 string in UTC, like "2026-06-23T14:30:00.000Z". It's the format you should use to store dates in a database, send them to an API, or put them in JSON — it's unambiguous and sorts correctly as text.
Overview
toISOString() turns a Date into the universal machine-readable date format: ISO 8601, always in UTC, like "2026-06-23T14:30:00.000Z" (the trailing Z means Zulu/UTC time). This is the format to reach for whenever a date leaves your program — saved to a database, sent in a request, written to a file.
Why this one over the human-readable methods? Because it's unambiguous and standard. Unlike locale formats, every system parses it the same way, and because the parts run largest-to-smallest, ISO strings even sort chronologically as plain text. It round-trips cleanly too: new Date(isoString) parses it straight back into a Date.
A useful related fact: JSON.stringify() automatically calls toISOString() on Date values, so dates in serialized JSON are already ISO strings (you get them back as strings, not Dates — convert them yourself after parsing). For displaying a date to users in their local format, use toLocaleDateString() instead — toISOString() is for machines, not people.
Syntax
date.toISOString()
new Date(2026, 5, 23).toISOString() // "2026-06-23T00:00:00.000Z"
// round-trips back to a Date
new Date("2026-06-23T14:30:00.000Z")
Example
<pre id="out" style="font:14px ui-monospace,monospace"></pre>
<script>
const d = new Date(Date.UTC(2026, 5, 23, 14, 30));
const iso = d.toISOString();
const back = new Date(iso);
document.getElementById('out').textContent =
'ISO: ' + iso + '\n' +
'parsed year: ' + back.getUTCFullYear();
</script>
Best practices
- Use
toISOString()to store, send and serialize dates — it's standard and unambiguous. - ISO strings sort chronologically as text, which is handy for ordering.
- Parse them back with
new Date(isoString). - For showing dates to users, use toLocaleDateString() instead — ISO is for machines.
Frequently asked questions
What format does toISOString() produce?
"2026-06-23T14:30:00.000Z" — the standard for storing and transmitting dates.Why use ISO strings to store dates?
How do I convert an ISO string back to a date?
new Date(isoString).