我有一个在数据库中定义的开始日期,我需要知道开始日期大于当前时间。我试过使用setInterval,但我无法访问setInterval函数之外的更新时间。javascript将当前时间与每分钟变量进行比较
这是我所需要的当前时间来比较数据库变量:
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
我在做什么错?
范围错误,您应该在setInterval之外定义“now”。 – Carlos2W
定义全局变量以获取外部值 –
您能否显示使用此组件的组件? – tobiasandersen