new Date() 在 Chrome 中有效,但在 Firefox 中抛出 'Invalid date'

new Date() works in Chrome but throws 'Invalid date' in Firefox

在应用程序中使用了 ng prime datepicker。

获取 2021 年 5 月 14 日星期五 00:00:00 GMT+0530(印度标准时间) 格式作为来自 api 的响应。

然后将 2021 年 5 月 14 日星期五 00:00:00 GMT+0530(印度标准时间) 此响应转换为新的 Date()。

然后将响应绑定到 ng prime datepiker。

在 chrome 工作正常。 在 Firefox 中显示“无效日期”。

请参阅 the Date constructor 的文档:

A string value representing a date, specified in a format recognized by the Date.parse() method. (These formats are IETF-compliant RFC 2822 timestamps, and also strings in a version of ISO8601.)

由于您没有传递其中一种格式,因此您依赖于对您的格式提供非标准支持的实现。

Chrome 确实如此。 Firefox 没有。

使用可让您指定格式的日期解析库(例如 date-fns/parse) or change the API so it outputs dates in the standard format