下面是一段倒计时,但是没有处理,出现00的情况,想了下找不到解决这个问题的切入点,所以像个为请教下,怎么处理这个。出现的00情况示例:比如当倒计时到了09:59:01,那么到下一秒的时候原本应该是09:58:59,可这却是09:59:00setTimeFunc = (time) => { const aimTime = new Date(('2018-5-24 09:30:00').replace(/-/g, '/')).getTime(); const currentTime = new Date().getTime(); // const days = null; // const hours = null; // const seconds = null; const diffTime = aimTime - currentTime; const years = new Date(aimTime).getFullYear() - new Date().getFullYear(); const month = new Date(aimTime).getMonth() - new Date().getMonth(); if (years === 0) { if (month === 0) { const days = Math.floor(diffTime / (1000 * 60 * 60 * 24)); const hours = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); const minutes = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24) - (hours * 1000 * 60 * 60)) / (1000 * 60)); const seconds = Math.floor((diffTime - (days * 1000 * 60 * 60 * 24) - (hours * 1000 * 60 * 60) - (minutes * 1000 * 60)) / 1000); console.log(hours); this.setState({ days: days > 9 ? days : '0' + days, hours: hours > 9 ? hours : '0' + hours, minutes: (minutes) > 9 ? minutes : '0' + minutes, seconds: seconds> 9 ? seconds : '0' + seconds }); } }
添加回答
举报
0/150
提交
取消