JS: Check if date is less than 1 hour ago?

后端 未结 7 1591
借酒劲吻你
借酒劲吻你 2020-12-13 05:38

Is there a way to check if a date is less than 1 hour ago?

Something like this:



        
7条回答
  •  不思量自难忘°
    2020-12-13 05:48

    //for adding hours to a date
    Date.prototype.addHours= function(hrs){
        this.setHours(this.getHours()+hrs);
        return this;
    }
    

    Call function like this:

    //test alert(new Date().addHours(4));
    

提交回复
热议问题