首页 > 解决方案 > 我的日期功能不适用于 Firefox,但适用于 chrome

问题描述

我在我的反应代码中使用 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 中都能正常工作。

标签: reactjsdate

解决方案


以这种格式使用日期yyyy/MM/dd(you can have any format of date) HH:mm:ss(this is required),这将适用于所有浏览器,

var getselectdate = "Jun-27-2019 12:00:00";

推荐阅读