计算两个日期相差多少天多少小时多少分钟多少秒
function dateDiff(d1,d2){
var date1 = new Date(d1);
if(d2){
var date2 = new Date(d2);
}else{
var date2 = new Date();
}
var ms = Math.abs(date1.getTime() - date2.getTime());
var hm=1000;
var mi=hm*60;
var hh=mi*60;
var dd=hh*24;
var day=parseInt(ms/dd);
var hour= (ms-day*dd)/hh;
var minute = (ms - day * dd - hour * hh) / mi;
var second = (ms - day * dd - hour * hh - minute * mi) / hm;
var milliSecond = ms - day * dd - hour * hh - minute * mi - second * hm;
return day+"天"+hour+"小时"+minute+"分钟"+second+"秒"+milliSecond+"毫秒"
}
console.log( dateDiff("2008.8.8","2008/7/8"));
console.log(dateDiff("2020.6.9")) ;