获取当前时间年月日周时分秒

 获取当前时间年月日周时分秒

    getDateTime () {
      let nowDate = ''
      let nowWeek = ''
      let nowTime = ''
      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 week = new Date().getDay() //周
      let hh = new Date().getHours() // 时
      let mf = new Date().getMinutes() < 10 ? '0' + new Date().getMinutes() : new Date().getMinutes() // 分
      let ms = new Date().getSeconds() < 10 ? '0' + new Date().getSeconds() : new Date().getSeconds() // 秒
        // 整理周
      if (week === 1) {
        nowWeek = '星期一'
      } else if (week === 2) {
        nowWeek = '星期二'
      } else if (week === 3) {
        nowWeek = '星期三'
      } else if (week === 4) {
        nowWeek = '星期四'
      } else if (week === 5) {
        nowWeek = '星期五'
      } else if (week === 6) {
        nowWeek = '星期六'
      } else {
        nowWeek = '星期日'
      }
      nowDate = yy + '年' + mm + '月' + dd + '日'
      nowTime = hh + ':' + mf + ":" + ms
      this.nowDateTime = nowDate + ' ' + nowWeek + ' ' + nowTime
    }

你可能感兴趣的:(vue.js,time,获取当前时间)