Date

Date.prototype.toISOString

Returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long

Syntax

JavaScript
date.toISOString()

Return Value

A string representing the date in ISO 8601 format

Examples

Basic Usage
const date = new Date('2024-06-15T14:30:00Z');
console.log(date.toISOString()); // '2024-06-15T14:30:00.000Z'
Practical Example
const now = new Date();
const isoDate = now.toISOString().split('T')[0];
console.log(isoDate); // '2024-06-15'
Advanced Usage
const dates = [
  new Date('2024-01-01'),
  new Date('2023-06-15'),
];
const sorted = dates.sort((a, b) =>
  a.toISOString().localeCompare(b.toISOString())
);

Understanding Date.prototype.toISOString

The Date.prototype.toISOString method in JavaScript returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long. It belongs to the Date object and is one of the most widely used methods for working with date values in modern JavaScript and TypeScript applications.

The method signature is date.toISOString(). When called, it returns a string representing the date in iso 8601 format. Understanding when and how to use toISOString() helps you write more expressive, readable code.

Common use cases for Date.prototype.toISOString include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like date-tojson, date-tolocalestring, date-tolocaledatestring, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Date.prototype.toISOString is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Date Methods

Other methods in the Date object

Related Tools

More Date Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.