check whether the date entered by the user is current date or the future date

前端 未结 5 546
离开以前
离开以前 2020-12-18 19:50

I was browsing through the net to find a javascript function which can check whether the date entered by the user is current date or the future date but i didn\'t found a s

5条回答
  •  庸人自扰
    2020-12-18 20:02

    here's a version that only compares the date and excludes the time.

    Typescript

    const inFuture = (date: Date) => {
        return date.setHours(0,0,0,0) > new Date().setHours(0,0,0,0)
    };
    

    ES6

    const inFuture = (date) => {
        return date.setHours(0,0,0,0) > new Date().setHours(0,0,0,0)
    };
    

提交回复
热议问题