实时显示系统当前时间时间

vue 实时显示系统当前时间函数。

 

getClientTime () {
      const date = new Date()
      const weeks = [ '', '', '', '', '', '', '']
      const that = this
      this.date = {
        yyyy: date.getFullYear(),
        mm: date.getMonth() + 1,
        dd: date.getDate(),
        hh: date.getHours(),
        MM: date.getMinutes(),
        ss: date.getSeconds(),
        week: weeks[ date.getDay() ]
    }

      if (this.date.mm < 10) {
        this.date.mm = '0' + this.date.mm
      }
      if (this.date.dd < 10) {
        this.date.dd = '0' + this.date.dd
      }
      if (this.date.hh < 10) {
        this.date.hh = '0' + this.date.hh
      }
      if (this.date.MM < 10) {
        this.date.MM = '0' + this.date.MM
      }
      if (this.date.ss < 10) {
        this.date.ss = '0' + this.date.ss
      }
setTimeout(() => {
        that.getClientTime()
      }, 1000)
    },
    ```
    应在created函数中调用
    ```js
    //页面调用
    <div class="fs-28">{{ date.hh + ':'+ date.MM + ':'+ date.ss }}</div>
    <div class="fs-14">{{ date.yyyy + '-'+ date.mm + '-'+ date.dd }}</div>
    <div class="left fs-18 lh-42">星期{{ date.week }}</div>

 

posted @ 2020-11-04 15:04  健身编程Dog  阅读(474)  评论(0编辑  收藏  举报