countdown = total => { let totalTime = new moment(‘2018-01-01 00:00:00‘, ‘YYYY-DD-MM HH:mm:ss‘).add(parseInt(total, 10), ‘seconds‘) let now = new moment(‘2018-01-01 00:00:00‘, ‘YYYY-DD-MM HH:mm:ss‘) this.setState({ time: totalTime.format(‘mm:ss‘), }) const t = setInterval(() => { totalTime.subtract(1, ‘seconds‘) if (totalTime.valueOf() >= now.valueOf()) { this.setState({ time: totalTime.format(‘mm:ss‘), }) } else { clearInterval(t) } }, 1000); }
修改一下format,可以实现时的倒计时,网上找了一堆都是shit,复杂死,就自己写一个