Favorites

JavaScript Date.prototype.toISOString() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Date.prototype.toISOString()
JavaScript Date Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The toISOString() method returns a date as a standard ISO 8601 string in UTC, such as 2026-11-28T00:30:00.000Z. It's the best format for storing and sending dates.

Description

The toISOString() method returns the date in the ISO 8601 format, always in UTC (shown by the trailing Z). This format is unambiguous, sorts correctly as text and is parsed reliably by every browser, so it's the right choice for APIs and storage. JSON.stringify() uses it for dates.

Taking the first 10 characters gives a YYYY-MM-DD date, but remember it's the UTC date, which can differ from the local date near midnight.

To get a YYYY-MM-DD date in the user's own time zone, build it from getFullYear(), getMonth() and getDate() with padStart(), or use toLocaleDateString('sv-SE'), whose format happens to match. When reading the string back, new Date(isoString) recreates the exact moment.

Syntax

date.toISOString()

Return Value

A string in the ISO 8601 format YYYY-MM-DDTHH:mm:ss.sssZ, in UTC.

Exceptions

  • RangeErrorThrown if the date is invalid.

Example

const d = new Date(Date.UTC(2026, 10, 28, 9, 30));
console.log(d.toISOString());
console.log(d.toISOString().slice(0, 10));
console.log(JSON.stringify({ when: d }));

Browser Support

The following information will show you the current browser support for the Date.prototype.toISOString() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee