18

例如,

const d = new Date("2012-08-20T15:00:00-07:00");

d这是一个UTC时间,时间偏移 = 07:00。还需要Z这样2012-08-20T15:00:00-07:00Z吗?它是否正确?

如果我使用这个字符串Z并使用 JavaScript 中的方法解析它Date.parse(),它会引发错误。不知道出了什么问题!

4

2 回答 2

25

不,您不应该包含带有时区偏移的“Z”。

rfc3339

  Z           A suffix which, when applied to a time, denotes a UTC
              offset of 00:00; often spoken "Zulu" from the ICAO
              phonetic alphabet representation of the letter "Z".

“Z”是零时间偏移,因此将其包含在显式偏移(尤其是非零偏移)是没有意义的。

于 2013-02-05T18:45:02.347 回答
13

引用W3C 关于日期和时间格式的说明

YYYY-MM-DDThh:mm:ss.sTZD(例如 1997-07-16T19:20:30.45+01:00)

在哪里:

[...]

TZD  = time zone designator (Z or +hh:mm or -hh:mm)

注意上面的or词。您可以指定时区偏移量或Zulu 无偏移量)。Z

于 2013-02-05T18:47:57.993 回答