我正在尝试从字符串创建一个新的日期对象,如下所示:
var myDate= new Date("1985-01-01T00:00:00.000-06:00");
在 FireFox 上,它会发出以下警告
Tue Jan 01 1985 00:00:00 GMT-0600 (Central Standard Time)
在 IE8 上,它会发出以下警告
NaN
为什么 IE 会这样?
最佳答案
展望 documetation正确的格式如下:
new Date(year, month, day [, hour, minute, second, millisecond ])
因此,如果您运行以下代码,它将在所有浏览器中正常运行:
var myDate= new Date(1985, 01, 01 , 00, 06, 00, 0000000000);
myDate // you get the right date in all browsers IE8/7 included
关于来自字符串的 Javascript 新日期对象,在 IE 和 FF 上的不同结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9912078/