Date.prototype.toISOString()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

toISOString() 方法返回一个 ISO(ISO 8601 Extended Format)格式的字符串: YYYY-MM-DDTHH:mm:ss.sssZ。时区总是 UTC(协调世界时),加一个后缀“Z”标识。

尝试一下

语法

dateObj.toISOString()

示例

使用 toISOString()

js
const d = new Date(0);

console.log(d.toISOString()); // "1970-01-01T00:00:00.000Z"

规范

Specification
ECMAScript Language Specification
# sec-date.prototype.toisostring

浏览器兼容性

BCD tables only load in the browser

参见