js日期对象兼容性的处理

来源:互联网 发布:李从厚 知乎 编辑:程序博客网 时间:2024/06/08 23:19
function NewDate(str) { str = str.split('-');
var date = new Date();
date.setUTCFullYear(str[0], str[1] - 1, str[2]);
 date.setUTCHours(0, 0, 0, 0);
return date;
 }


所以,为保证在各个浏览器中兼容,其实就是指为了兼容IE,我们在使用Date()对象时最好统一使用

new Date(year, month, day, hour, minute, sec, millsec)

new Date(millsec)(millsec为距1970年1月1 日至今的毫秒数).



在ie下 new Date(""date text"") 时返回的成果是一个特别的日期对象,只是ie调试器将之显示成了NaN, 对其调用返回number的办法将都邑返回NaN.