如何比较2个日期以检查事件是否通过

时间:2017-11-10 10:50:27

标签: javascript jquery momentjs

我试图仅显示notifications users <}输入的today's匹配此格式的某些日期2017/11/13 15:02来自{ {1}}

注意:record将始终更改,用于比较

伪代码

2017/11/13 15:02

我尝试过类似的内容

 if(today's date passed and dont match 2017/11/13 15:02){
    //don't send notification
 }else{
   //send notification
}

1 个答案:

答案 0 :(得分:0)

getTime()方法将为您提供自纪元以来以毫秒为单位的时间戳,您可以将其与新Date,Date.parse()一起使用,但是已经返回时间戳。

var comparisionDate = Date.parse('2017/11/13 15:02');

var todaysDate = new Date();  // current date

// further i don't know to compare

if(comparisionDate == todaysDate.getTime() ){
   //send notifications
   
   alert("Today's date " + todaysDate.getTime() + " equals " + comparisionDate);
}else{
  // don't show notification
  alert("Today's date " + todaysDate.getTime() + " Not equals " + comparisionDate);
}