admin管理员组

文章数量:1296856

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}

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}
Share Improve this question edited Oct 21, 2012 at 18:26 Krishna Kumar asked Oct 10, 2012 at 14:49 Krishna KumarKrishna Kumar 2,1311 gold badge23 silver badges34 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 5

This works in all browsers -

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

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 ment below for more information.

Make sure the parameter is RFC1123 pliant: https://www.rfc-editor/rfc/rfc1123

本文标签: datetimeJavaScript date function returns quotDate Invalid Datequot in Firefox browserStack Overflow