js计算过期时间

378 阅读1分钟
getExpiredTime(curTime1,month){//已知日期 和月数 计算国企时间
      const curTime = '2020-10-12 10:00:05'
      const months = 2
      
      const getDay = new Date(curTime.replace(/-/g, '/')).getTime();//见日期转为时间戳
      //按照自然月计算
      var date = new Date(getDay);//直接用 new Date(时间戳) 格式转化获得当前时间
      let expiredTime = date.setMonth(date.getMonth() + months)
      //expiredTime = date.setDate(date.getDate() + 1)
      return this.getLocalTime(expiredTime)
    },
    getLocalTime(nS) {
      return new Date(parseInt(nS)).toLocaleString().replace(/年|月/g, "/").replace(/日/g, " ");
    },

参考链接:www.cnblogs.com/chen-cheng/…