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

前端 未结 5 545
离开以前
离开以前 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-18 20:14

    try out this

    function isFutureDate(idate){
    var today = new Date().getTime(),
        idate = idate.split("/");
    
    idate = new Date(idate[2], idate[1] - 1, idate[0]).getTime();
    return (today - idate) < 0 ? true : false;
    }
    

    Demo

    console.log(isFutureDate("02/03/2016")); // true
    console.log(isFutureDate("01/01/2016")); // false
    

提交回复
热议问题