获得星期几的js

224 阅读1分钟
    getTime() {
      this.date = new Date()
      this.date = dateformat(this.date, 'yyyy-mm-dd')
      this.time = new Date()
      this.time = dateformat(this.time).substring(11)
      const weekday = [
        '星期天',
        '星期一',
        '星期二',
        '星期三',
        '星期四',
        '星期五',
        '星期六'
      ][new Date().getDay()]
      this.week = weekday
      const date2 = new Date()
      var self = this
      if (date2.getHours() >= 0 && date2.getHours() < 12) {
        self.hoursTip = '上午好'
      } else if (date2.getHours() >= 12 && date2.getHours() < 18) {
        self.hoursTip = '下午好'
      } else {
        self.hoursTip = '晚上好'
      }
    }