指定日期+N天后是多少天

        // 指定日期+n天后
        function AddDays(startDate, dayIn) {
            var date = new Date(startDate);
            var myDate=new Date(date.getTime()+dayIn*24*60*60*1000);
            function msToDate(msec) {
                let datetime = new Date(msec);
                let year = datetime.getFullYear();
                let month = datetime.getMonth();
                let date = datetime.getDate();
                let hour = datetime.getHours();
                let minute = datetime.getMinutes();
                let second = datetime.getSeconds();

                let result1 = year +
                             '-' +
                             ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
                             '-' +
                             ((date + 1) < 10 ? '0' + date : date) +
                             ' ' +
                             ((hour + 1) < 10 ? '0' + hour : hour) +
                             ':' +
                             ((minute + 1) < 10 ? '0' + minute : minute) +
                             ':' +
                             ((second + 1) < 10 ? '0' + second : second);

                let result2 = year +
                             '-' +
                             ((month + 1) >= 10 ? (month + 1) : '0' + (month + 1)) +
                             '-' +
                             ((date + 1) < 10 ? '0' + date : date);

                let result = {
                    hasTime: result1,
                    withoutTime: result2
                };

                return result;
            }

            return msToDate(myDate).hasTime;

        }

var today='2018-8-28',90天后的日期是?

AddDays(today,90);
posted @ 2018-07-17 14:40  cacti_vc  阅读(365)  评论(0编辑  收藏  举报