Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用momentjs检查日期是否至少是过去的一天?_Javascript_Jquery_Date_Momentjs - Fatal编程技术网

Javascript 如何使用momentjs检查日期是否至少是过去的一天?

Javascript 如何使用momentjs检查日期是否至少是过去的一天?,javascript,jquery,date,momentjs,Javascript,Jquery,Date,Momentjs,通常如何使用momentjs检查随机日期是否至少是过去的一天(24小时) 比如: const today = moment() const isAtLeastADayAgo = today.subtract(dateToCheck) > 1 // ?? 你可以简单地使用 函数isADayAgo(输入){ 让昨天=时刻()减去(1,'d'); 返回input.isBefore(昨天); } const isAtLeastADayAgo=isADayAgo(矩()); console.lo

通常如何使用momentjs检查随机日期是否至少是过去的一天(24小时)

比如:

const today = moment()
const isAtLeastADayAgo = today.subtract(dateToCheck) > 1 // ??
你可以简单地使用

函数isADayAgo(输入){
让昨天=时刻()减去(1,'d');
返回input.isBefore(昨天);
}
const isAtLeastADayAgo=isADayAgo(矩());
console.log(isatalastadayago)

我建议您使用纯javascript日期构造函数

var today =  new Date();
var pastDate = // some past date
// 86400 seconds in 24hrs
// getTime() will return you date in milliseconds
if(86400000 < today.getTime()-pastDate.getTime()) will return true if past date is older than 24Hrs.
var today=新日期();
var passdate=//一些过去的日期
//24小时86400秒
//getTime()将以毫秒为单位返回日期
如果过去的日期早于24小时,if(86400000
我的投票,但我会将其编码为
if(today-pastDate>86400000)
,尽管它在夏令时边界上可能不准确。要解决这个问题:
if(pastDate
;-)@RobG我只是按照eslint的建议在右边写常量。顺便说一句,我喜欢你的回答(更干净)。
var today =  new Date();
var pastDate = // some past date
// 86400 seconds in 24hrs
// getTime() will return you date in milliseconds
if(86400000 < today.getTime()-pastDate.getTime()) will return true if past date is older than 24Hrs.