计算两个时间点的时间差
diff-time.js复制
function diffTime(time1) {
return function(time2) {
let seconds = Math.abs(time1 - time2) / 1000;
const days = Math.floor(seconds / (3600 * 24));
seconds = seconds - days * 3600 * 24;
const hours = Math.floor(seconds / 3600);
seconds = seconds - hours * 3600;
const minutes = Math.floor(seconds / 60);
seconds = seconds - minutes * 60;
return {
days,
hours,
minutes,
seconds: parseInt(seconds)
};
};
}
大牛们的评论:朕有话说
还没有人评论哦,赶紧抢沙发!