Last Updated : 11 Jul, 2025
The 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). The date object is created using the date() constructor.
JavaScript
let dateobj = new Date('October 15, 1996 05:35:32');
let B = dateobj.toISOString();
console.log(B);
1996-10-15T05:35:32.000ZSyntax
dateObj.toISOString()Parameters
Note: The DateObj is a valid Date object created using the Date()constructor.
Example 1: Here nothing as a parameter is passed while creating a date object but still toISOString() method returns the current day name, month name, date, year, and time.
javascript
// Here nothing has been assigned
// while creating Date object
let dateobj = new Date();
// Contents of above date object is
// converted into a string using toISOString() method.
let B = dateobj.toISOString();
// Printing the converted string.
console.log(B);
Output:
2018-04-23T10:26:00.996Z
Example 2: Here we will pass a date object toISOString() method to return the day name, month name, date, year, and time.
javascript
// Here nothing has been assigned
// while creating Date object
let dateobj =
new Date('October 13, 1996 05:35:32 GMT-3:00');
// Contents of above date object is
// converted into a string using toISOString() method.
let B = dateobj.toISOString();
// Printing the converted string.
console.log(B);
Output:
1996-10-13T08:35:32.000Z
Note: Months, Dates, hours, minutes, seconds, and milliseconds should all be in their respective range of 0 to 11, 1 to 31, 0 to 23, 0 to 59, 0 to 59, 0 to 999 respectively.
Supported BrowsersRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4