js 获取现在时间一个月(N天)后的日期

    let today = new Date().getTime()
    let lastDay = getTimeByDay(30) //获取30天后的日期
    let lastTime = formatTime(lastDay)
    
    console.log(lastTime);//2019-03-23

    /* 
    num 获取当天多少天后的日期
    */
    function getTimeByDay(num) {
        return today + 60 * 60 * 1000 * 24 * num;
    }

    function formatTime(time) {
        //new Date(time).toISOString()    => 2019-02-23T08:40:35.825Z
        return new Date(time).toISOString().split('T')[0];
    }

猜你喜欢

转载自www.cnblogs.com/wangzhichao/p/10413595.html