JavaScript validate date and return last available date of calendar

前端 未结 4 818
栀梦
栀梦 2021-01-27 03:19

I want to validate my date if date not exits in calendar then return me last available date of calendar,

Example 01

Input Date    : 31         


        
4条回答
  •  一生所求
    2021-01-27 03:56

    function isValidDate(year, month, day) {
        var d = new Date(year, month, day);
        if (d.getFullYear() == year && d.getMonth() == month && d.getDate() == day) {
            return d;
        }
        else
            rturn new Date(year, month, 0);;
    }
    

提交回复
热议问题