Javascript UTC 时区在 Firefox 中不起作用

Javascript UTC timezone does not work in 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)

也许你可以使用时刻:https://www.npmjs.com/package/moment

var d = new Date(`Wed Aug 12 2020 18:34:35 GMT-0400 (Eastern Daylight Time) UTC`);

var date = moment(d).utc().format()

console.log("date: ", date )

您正在尝试做:

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