Find out the previous year date from current date in javascript

后端 未结 12 1368
执念已碎
执念已碎 2021-02-02 07:43

I need to find out the previous year date from current date and then set as minDate in jQuery UIdatepicker in javascript

My date formaqt is dd-mm-yy

<
12条回答
  •  日久生厌
    2021-02-02 08:42

      function getTodayDate() {
            var today = new Date();
            var dd = today.getDate();
            var mm = today.getMonth() + 1; //January is not 0!
            var yyyy = today.getFullYear();
            if (dd < 10) { dd = '0' + dd }
            if (mm < 10) { mm = '0' + mm }
            today = yyyy + '-' + mm + '-' + dd;
            return today;
        };
        function getYearAgo(){
        var lastYear = new Date();
        var dd = lastYear.getDate();
        var mm = lastYear.getMonth() + 1; //January is not 0!
        var yyyy = lastYear.getFullYear(getTodayDate) - 1;
        if (dd < 10) { dd = '0' + dd }
        if (mm < 10) { mm = '0' + mm }
        lastYear = yyyy + '-' + mm + '-' + dd;     
        return lastYear;
        }
    

提交回复
热议问题