Below is the example of Date toISOString() method.
The date.toISOString() method is used to convert the given date 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 date() constructor.
Parameters: This method does not take any parameter. It is just used along with a Date object created using Date() constructor.
Return Values: It returns the converted string of Date() constructor contents into ISO format (ISO 8601).
Note: The DateObj is a valid Date object created using Date()constructor. More codes for the above method are as follows:
Program 1: Here nothing as a parameter is passed while creating date object but still toISOString() method return current day name, month name, date, year, and time.
Program 2: Here we will pass a date object toISOString() method return day name, month name, date, year, and time.
Note: Months, Dates, hours, minutes, seconds, 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.
- Google Chrome 3 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 9 and above
- Opera 10.5 and above
- Safari 5 and above