javascript Date.toISOString() return 差异日期值

javascript Date.toISOString() return difference date value

我对下面示例中显示的 javascript Date.toISOString() 函数感到困惑,为什么 ISO 格式的 x 日期值变成一月?

const date = new Date();
const x = (new Date(date.getFullYear(), date.getMonth() , 1));

console.log(date); \Tue Feb 04 2020 11:11:12 GMT+0800 (Malaysia Time)
console.log(x); \Sat Feb 01 2020 00:00:00 GMT+0800 (Malaysia Time)

console.log(date.toISOString()); \2020-02-04T03:11:12.330Z
console.log(x.toISOString()); \2020-01-31T16:00:00.000Z

这是由于从 GMT+08 到 UTC 的时区转换。 toISOString 函数将日期转换为 UTC(作为注释,您可以通过字符串末尾的 "Z" 确定日期在 UTC 时区中)。

Feb 01 2020 00:00:00 GMT+0800 转换为 ISO 字符串时,日期减少了 8 小时,因此变为 Jan 31 2020 16:00:00