扩展Date的DateDiff方法--日期差

Date.prototype.DateDiff = function(after){
var diffDay;
var beforeDate = new Date(this).format("yyyy-MM-dd");
beforeDate = beforeDate.split('-');
beforeDate = new Date(beforeDate[1] + '-' + beforeDate[2] + '-' + beforeDate[0]).toLong();
console.log("beforeDate");
console.log(beforeDate);
var afterDate = new Date(after).format("yyyy-MM-dd");
afterDate = afterDate.split("-");
afterDate = new Date(afterDate[1] + '-' + afterDate[2] + '-' + afterDate[0]).toLong();
console.log("afterDate");
console.log(afterDate);
diffDay = parseInt(Math.abs(afterDate - beforeDate) / 1000 / 60 / 60 /24);
console.log("diffDay");
console.log(diffDay);
return diffDay + 1 +"天";
};
posted @ 2016-09-28 17:29  limeOracle  阅读(762)  评论(0编辑  收藏  举报