【JS】根据某个时间,获取某个时间N分钟以后的时间

var b = 30,(30分钟)

var time = new Date('2020-2-1 12:00:00')
      var b = 30 //分钟数
      time.setMinutes(time.getMinutes() + b, time.getSeconds(), 0)
      var date = time
      var year = date.getFullYear()
      var month =date.getMonth() + 1 > 9? date.getMonth() + 1: '0' + (date.getMonth() + 1)
      var day = date.getDate() > 9 ? date.getDate() : '0' + date.getDate()
      // var todayDate = year + '-' + month + '-' + day
      var hour = date.getHours() > 9 ? date.getHours() : '0' + date.getHours()
      var min =date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes()
      var sec =date.getSeconds() > 9 ? date.getSeconds() : '0' + date.getSeconds()
      var todayDate =year + '-' + month + '-' + day + ' ' + hour + ':' + min + ':' + sec

      console.log(todayDate)
      //把2020-02-01 12:30:00 转换成 秒 1580531400000
      console.log(time.getTime())

      return todayDate

你可能感兴趣的:(JS,javascript,vue.js,开发语言)