How to check if input date is equal to today's date?

后端 未结 10 1163
忘了有多久
忘了有多久 2020-11-28 05:13

I have a form input with an id of \'date_trans\'. The format for that date input (which is validated server side) can be any of:

  • dd/mm/yyyy
  • dd-mm-yyyy
10条回答
  •  天涯浪人
    2020-11-28 05:18

    The following solution compares the timestamp integer divided by the values of hours, minutes, seconds, millis.

    var reducedToDay = function(date){return ~~(date.getTime()/(1000*60*60*24));};
    return reducedToDay(date1) == reducedToDay(date2)
    

    The tilde truncs the division result (see this article about integer division)

提交回复
热议问题