Example 1 — Basic toISOString() Output
Serialize a UTC instant built with Date.UTC.
const date = new Date(Date.UTC(2026, 2, 15, 12, 0, 0));
console.log(date.toISOString());
// "2026-03-15T12:00:00.000Z" How It Works
- Build a UTC instant.
Date.UTC(2026, 2, 15, 12, 0, 0)is noon on Mar 15, 2026 in UTC (month index2). - Wrap it in a Date.
new Date(...)stores that millisecond instant. - Serialize.
toISOString()returns the portable…Zstring. - No side effects. The
Dateis unchanged; only a string is returned.

