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

后端 未结 10 1173
忘了有多久
忘了有多久 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:24

    for completeness, taken from this solution:

    You could use toDateString:

    var today = new Date();
    var isToday = (today.toDateString() == otherDate.toDateString());
    

    no library dependencies, and looking cleaner than the 'setHours()' approach shown in a previous answer, imho

提交回复
热议问题