js 转北京时间

    add0(val) {
      return val < 10 ? '0' + val : val;
    },
    // 转换北京时间
    BjTime(val) {
      // console.log(val)
      if(val) {
        const add0 = num => num < 10 ? '0' + num : num
        let date, y, m, d, h, mm, s
        let time = new Date(val).getTime()
        date = new Date(time)
        y = date.getFullYear()
        m = add0(date.getMonth() + 1)
        d = add0(date.getDate())
        h = add0(date.getHours())
        mm = add0(date.getMinutes())
        s = add0(date.getSeconds())
        return `${y}-${m}-${d} ${h}:${mm}:${s}`
      } else {
        return ''
      }
    },

 

posted @ 2022-07-14 15:44  _曾经沧海难为水  阅读(565)  评论(0编辑  收藏  举报