我在数据库中定义了开始日期,我需要知道开始日期何时大于当前时间 . 我尝试过使用setInterval,但我无法访问setInterval函数之外的更新时间 .
这是我需要将当前时间与数据库变量进行比较:
if(startDate > now) {
var status = 'pre';
}
我尝试使用setInterval如下,但我无法访问setInterval函数之外的更新(当前时间) .
setInterval(function(){
now = moment(new Date()).format();
console.log('time1 ', now); // this works
}, 1000);
console.log('time2 ', now); // this doesn't
我究竟做错了什么?
2 回答
我最终使用react-interval https://github.com/nkbt/react-interval来完成此任务 .
试试这个..