📅  最后修改于: 2023-12-03 15:32:21.933000             🧑  作者: Mango
The toISOString()
method is a built-in date method in JavaScript that returns a string in ISO format (International Organization for Standardization).
The toISOString()
method returns a string representation of the date in ISO format. This format is widely used for exchanging data between systems and is recognized by most programming languages.
dateObj.toISOString()
The toISOString()
method does not take any parameters.
The toISOString()
method returns a string representing the date in the following format:
yyyy-mm-ddThh:mm:ss.sssZ
Where:
yyyy
- year (four digits)mm
- month (two digits)dd
- day (two digits)T
- separator between date and timehh
- hours (two digits)mm
- minutes (two digits)ss
- seconds (two digits)sss
- milliseconds (three digits)Z
- UTC offset (always "Z" for UTC)const date = new Date('2021-03-01T12:00:00Z')
const str = date.toISOString()
console.log(str) // "2021-03-01T12:00:00.000Z"
In this example, we create a new Date
object with a date string in ISO format. We then call the toISOString()
method on this object and store the resulting string in str
. Finally, we log this string to the console.
The toISOString()
method is supported in all modern browsers, including Chrome, Firefox, Safari, and Edge. It is also supported in Internet Explorer 9 and higher.
In conclusion, the toISOString()
method is a useful built-in method in JavaScript that converts a Date
object to a string in ISO format. This format is widely used for exchanging data between systems and is recognized by most programming languages.