JavaScript Date toISOString() Method

JavaScript Date toISOString() method is used to convert the given data object’s contents into a string in ISO format (ISO 8601), i.e., in the form of (YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ).

Syntax

dateObj.toISOString()

Parameters

This method does not take any parameters. It is used with a Date object created using the Date() constructor.

Return value

It returns the converted string of Date() constructor contents into ISO format (ISO 8601).

Example 1: Convert Current Date to ISO String

let currentDate = new Date();
let isoString = currentDate.toISOString();

console.log(isoString);

Output

2023-08-16T05:54:04.923Z

Example 2: Convert Specific Date to ISO String

let specificDate = new Date('December 25, 2025 23:59:59');
let isoString = specificDate.toISOString();

console.log(isoString);

Output

2025-12-25T18:29:59.000Z

Example 3: Adjust the Date and Convert to ISO String

This example sets a specific time and then converts the date to an ISO string:

let date = new Date();

date.setHours(14);
date.setMinutes(30);
date.setSeconds(15);

let isoString = date.toISOString();

console.log(isoString);

Output

2023-08-16T09:00:15.143Z

Browser Compatibility

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes 9-11

That’s it!

Related posts

JavaScript Date toTimeString()

JavaScript Date toUTCString()

JavaScript Date toLocaleDateString()