【发布时间】:2019-11-09 08:38:15
【问题描述】:
我在我的反应代码中使用 Date() 函数。日期函数在 chrome 上运行良好,但在 firefox 上运行。
我尝试将日期转换为毫秒。
var getnewdate = "Wed Jun 26 2019 00:00:00 GMT+0530 (India Standard Time)";
alert(getnewdate);
var getCurrentDayInMilli = new Date(getnewdate).getTime() / 100000;
alert(getCurrentDayInMilli);
警报(getnewdate);在 chrome 上打印“Tue Jun 25 2019 00:00:00 GMT+0530 (India Standard Time)”是正确的,但在 Firefox 上打印的是“Invalid Date”,这是不正确的。
我希望我的警报功能在 Firefox 和 chrome 中都能正常工作。
【问题讨论】:
-
来自MDN: "[...] 使用
Date构造函数解析日期字符串 [...] 由于浏览器的差异和不一致,我们强烈反对。"我> -
更新帖子后,在 Firefox 中也可以正常工作。
-
是的,但是我更新的帖子在 Firefox 中创建问题