ISO 格式“+00:00”和 "Z" 之间的区别?

Difference between ISO formatting "+00:00" and "Z"?

这种日期格式有什么区别:

"2021-01-01T00:00:00.000Z"

还有这个:

"2021-01-01T00:00:00+00:00"

它们都是有效的 ISO 格式吗?当我在 JavaScript 中调用 new Date().toISOString() 时,我得到了第一个

出于某种原因,我无法找到明确的答案。

来自Wikipedia

An offset of zero, in addition to having the special representation "Z", can also be stated numerically as "+00:00", "+0000", or "+00".

ECMA-262 定义了一个由 toISOString 生成的 "string interchange format" 并且还必须由内置解析器解析。它指出:

Z is the UTC offset representation specified as "Z" (for UTC with no offset) or an offset of either "+" or "-" followed by a time expression HH:mm (indicating local time ahead of or behind UTC, respectively)

因此,当 toISOString 生成“Z”时,解析器还将接受“+00:00”和“-00:00”。任何其他格式的正确解析都取决于实现(因此不可靠)。