vue 获取当前年月日

 

systemTime = ''


// 当前时间
addDate () {
  let nowDate = new Date()
  let date = {
    year: nowDate.getFullYear(),
    month: nowDate.getMonth() + 1,
    date: nowDate.getDate()
  }
  this.systemTime = date.year + '-' + date.month + '-' + date.date
}


mounted () {
  this.addDate()
}

 

// 获取当前时间
    gettime = ''
    getTime () {
      let _this = this
      let yy = new Date().getFullYear()
      let mm = (new Date().getMonth() + 1) < 10 ? '0' + (new Date().getMonth() + 1) : (new Date().getMonth() + 1)
      let dd = new Date().getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
      let hh = new Date().getHours() < 10 ? '0' + new Date().getHours() : new Date().getHours()
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes()
      let ss = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds()
      _this.gettime = yy + mm + dd + hh + mf + ss
    }

 

你可能感兴趣的:(vue)