JavaScript date function returns “Date {Invalid Date}” in Firefox browser

偶尔善良 提交于 2019-12-19 20:36:13

问题


Facing a problem with JavaScript Date function, returns "Date {Invalid Date}" in Firefox browser but works fine in Google chrome.

// My Input is
new Date("Sat Jan 01 00:00:00 EST 1");

// Works fine in google chrome 
// Result: Mon Jan 01 2001 10:30:00 GMT+0530 (India Standard Time)

// Not working in Firefox (Version: 15.0.1)
// Result: Date {Invalid Date}

回答1:


Date does not take a timezone parameter in that way. My thought is that Chrome is just ignoring it.

new Date(year, month, day [, hour, minute, second, millisecond])

Please see @Brett's comment below for more information.




回答2:


This works in all browsers -

new Date('2001/01/31 12:00:00 AM')




回答3:


Make sure the parameter is RFC1123 compliant: http://tools.ietf.org/html/rfc1123



来源:https://stackoverflow.com/questions/12822225/javascript-date-function-returns-date-invalid-date-in-firefox-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!