检查时间戳是否早于24小时-Javascript
我正在使用检查时间戳是否早于24小时-Javascript,javascript,timestamp,nedb,Javascript,Timestamp,Nedb,我正在使用Date.now()函数获取api调用时的时间戳。我将它存储在由nedb promises提供支持的数据库中。我如何在代码后面使用它来检查更新存储数据是否需要新的api调用?我想每天至少检查一次 db.definitions.find({}).then( (results) => { if( results.length > 0 ){ console.log(results); if( Math.round(new Date().getTime() /
Date.now()
函数获取api调用时的时间戳。我将它存储在由nedb promises
提供支持的数据库中。我如何在代码后面使用它来检查更新存储数据是否需要新的api调用?我想每天至少检查一次
db.definitions.find({}).then( (results) => {
if( results.length > 0 ){
console.log(results);
if( Math.round(new Date().getTime() / 1000) - results.lastUpdate >= 86400 ){
updateDefinitions().then( (filters) => {
db.definitions.update({}, { $set: {filters} }, { returnUpdatedDocs: true }).then( (result) => {
console.log(result);
advServers.push(results.filters.easylist);
trackingServers.push(results.filters.easyprivacy);
});
});
}else{
console.log("definitions already up to date");
advServers.push(results.easylist);
trackingServers.push(results.easyprivacy);
}
}else{
updateDefinitions().then( (filters) => {
console.log(filters);
db.definitions.insert({ filters }).then( (result) => {
console.log(result);
advServers.push(results.filters.easylist);
trackingServers.push(results.filters.easyprivacy);
});
});
}
});
到目前为止,您尝试了什么?@evolutionxbox查看代码我不确定您需要什么,但setTimout()和/或setInterval()可能会有所帮助,它们都使用计时器调用函数,但它们在特定的内在方式下工作不一样。您可以查看文档:@ErniSouza我需要检查时间戳是否有弹性,是否超过24小时。我知道你建议的函数,但这不是它们的用例,我需要做一个检查,而不是设置超时或间隔。