我需要根据前一次检查当前时间。
const created = moment(new Date());
const oneMinuteLater = created.add(1, 'minutes');
setTimeout(() => {
const now = moment();
// Returns false
console.log('oneMinutePass', now.isAfter(oneMinuteLater, 'minute'));
}, 60000);
如果一分钟过去,为什么它会返回false?
答案 0 :(得分:3)
一分钟后,now
等于到oneMinuteLater
, 。
开始
now = 15/01/2018 11:08:00
oneMinuteLater = 15/01/2018 11:08:01
一分钟后
now = 15/01/2018 11:08:01
oneMinuteLater = 15/01/2018 11:08:01
//now === oneMinuteLater
解决方案是使用isSameOrAfter()