function getTimeRemaining(endtime) {
const total = Date.parse(endtime) - Date.parse(new Date());
const seconds = Math.floor((total / 1000) % 60);
const minutes = Math.floor((total / 1000 / 60) % 60);
const hours = Math.floor((total / (1000 * 60 * 60)) % 24);
const days = Math.floor(total / (1000 * 60 * 60 * 24));
return {
total,
days,
hours,
minutes,
seconds,
};
}
a = getTimeRemaining('2020-12-10 10:00:00');
console.log(a)

本文介绍了一个JavaScript函数,用于计算指定结束时间与当前时间之间的剩余天数、小时、分钟及秒数,并通过实例演示了如何使用该函数。
1678

被折叠的 条评论
为什么被折叠?



