首页 > 解决方案 > Javascript UTC 时区在 Firefox 中不起作用

问题描述

下面的代码不适用于 Firefox,与 Chrome 完美兼容。有人可以帮我找到替代解决方案吗?

const tempDate = getStartDate['startDate']; // Returns: 2020-08-13 12:52:38
new Date(`${tempDate} UTC`);

Expected Output: Thu Aug 13 2020 08:52:38 GMT-0400 (Eastern Daylight Time)

标签: javascriptdatetimetimezoneutc

解决方案


您正在尝试执行以下操作:

new Date('2020-08-13 12:52:38 UTC')

相反,您应该这样做:

new Date('2020-08-13T12:52:38Z')

https://www.ecma-international.org/ecma-262/11.0/index.html#sec-date-time-string-format


推荐阅读