js中计算两个日期之差

var aBgnDate, aEndDate;
           var oBgnDate, oEndDate;
           var nYlts;
           aBgnDate = strBgnDate.split('-');
           aEndDate = strEndDate.split('-');
           oBgnDate = new Date(aBgnDate[1] + '-' + aBgnDate[2] + '-' + aBgnDate[0]);
           oEndDate = new Date(aEndDate[1] + '-' + aEndDate[2] + '-' + aEndDate[0]);
           //把相差的毫秒数转换为天数
           nYlts = parseInt(Math.abs(oEndDate - oBgnDate) / 1000 / 60 / 60 / 24);
posted on 2016-07-20 16:20  yxtic  阅读(3209)  评论(0编辑  收藏  举报