Home  >  Article  >  Web Front-end  >  ie8 不支持new Date(2012-11-10)问题的解决方法_javascript技巧

ie8 不支持new Date(2012-11-10)问题的解决方法_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:27:361312browse

我们在使用JS的时候也碰到了如此问题,后来经过修改,在IE8环境里,下面的代码是可用的。

js 结束时间-开始时间,得到天数

复制代码 代码如下:

function getDays(strDateStart,strDateEnd){
var strSeparator = "-"; //日期分隔符
var oDate1;
var oDate2;
var iDays;
oDate1= strDateStart.split(strSeparator);
oDate2= strDateEnd.split(strSeparator);
var strDateS = new Date(oDate1[0], oDate1[1]-1, oDate1[2]);
var strDateE = new Date(oDate2[0], oDate2[1]-1, oDate2[2]);
iDays = parseInt(Math.abs(strDateS - strDateE ) / 1000 / 60 / 60 /24)//把相差的毫秒数转换为天数
return iDays ;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn