<script>
//作用求两个日期时间的时间间隔
function getSpaceBetweenDate(date1,date2) {
//1.得到两个日期之间的秒数
var between = Math.round(Math.abs(date1 - date2)/1000);
//2.把秒数转换成相差多少天 多少小时 多少分钟 多少秒
var day = Math.floor(between/(24*60*60));
var hour = Math.floor(between/60/60) % 24;
var minute = Math.floor(between/60)%60;
var second = between%60;
//3.包装一个对象返回
var obj = {
day:day,
hour:hour,
minute:minute,
second:second
}
return obj;
}
var date1 = new Date("2017-8-8 22:23:23");
var date2 = new Date("2017-10-8 23:30:30");
//使用自己写的方法求两个时间的差
var o = getSpaceBetweenDate(date1,date2);
console.log(o);
</script>