倒计时的两种方案
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了倒计时的两种方案相关的知识,希望对你有一定的参考价值。
export const countDown=(time)=>{ const t = (new Date(time).getTime() - new Date().getTime())/1000; const days = parseInt(t/3600/24); const hours = parseInt(t/60/60%24); const minutes = parseInt(t/60%60); const seconds = parseInt(t%60); const h = hours<10?`0${hours}`:hours; const m = minutes<10?`0${minutes}`:minutes; const s = seconds<10?`0${seconds}`:seconds; return (days>0&&`${days}天${h}小时${m}分钟${s}秒`)|| (hours>0&&`${h}小时${m}分钟${s}秒`)|| (minutes>0&&`${m}分钟${s}秒`)|| (seconds>0&&`${s}秒`) }; export const countDown2=(time)=>{ const t = parseInt(new Date(time).getTime()/1000 - new Date().getTime()/1000); const days = parseInt(t/(60*60*24)); const hours = parseInt(t/(60*60) - days*24); const minutes = parseInt(t/60 - hours*60 - days*24*60); const seconds = parseInt(t - minutes*60 - hours*3600 - days*24*3600); const h = hours<10?`0${hours}`:hours; const m = minutes<10?`0${minutes}`:minutes; const s = seconds<10?`0${seconds}`:seconds; return (days>0&&`${days}天${h}小时${m}分钟${s}秒`)|| (hours>0&&`${h}小时${m}分钟${s}秒`)|| (minutes>0&&`${m}分钟${s}秒`)|| (seconds>0&&`${s}秒`) };
以上是关于倒计时的两种方案的主要内容,如果未能解决你的问题,请参考以下文章