计算日期的相差天数

DateDiff:function(sDate1,  sDate2){    //sDate1和sDate2是2018-05-02格式  
           var  aDate,  oDate1,  oDate2,  iDays  
           aDate  =  sDate1.split("-")  
           oDate1  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])    //转换为02-05-2018格式  
           aDate  =  sDate2.split("-")  
           oDate2  =  new  Date(aDate[1]  +  '-'  +  aDate[2]  +  '-'  +  aDate[0])  
           iDays  =  parseInt(Math.abs(oDate1  -  oDate2)  /  1000  /  60  /  60  /24)    //把相差的毫秒数转换为天数  
           return  iDays  
        },
//两个时间相差天数 兼容firefox chrome
    function datedifference(sDate1, sDate2) {    //sDate1和sDate2是2006-12-18格式  
        var dateSpan,
            tempDate,
            iDays;
        sDate1 = Date.parse(sDate1);
        sDate2 = Date.parse(sDate2);
        dateSpan = sDate2 - sDate1;
        dateSpan = Math.abs(dateSpan);
        iDays = Math.floor(dateSpan / (24 * 3600 * 1000));
        return iDays
    };
原文地址:https://www.cnblogs.com/lin-dong/p/8979064.html