js 求两个日期相差的天数
转载 http://www.cnblogs.com/caoyuzhi/archive/2012/12/25/2831928.html <script type="text/javascript"> 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; } alert(getDays("2011-12-31", "2012-1-1")); </script>