时间戳转化为日期

获取时间戳

my.getServerTime({
      success: (res) => {
        this.setData({
          timestamp:res.time
        })
      },
    });

 

转换日期

function havetime(unixtime) {
    var date = new Date(unixtime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d + ' ' + h + ':' + minute + ':' + second;//年月日时分秒
    return y + '-' + m + '-' + d + ' ' + h + ':' + minute;

  }
  this.setData({
    time:havetime(this.data.timestamp)
  })

 

posted @ 2019-12-12 09:00  千金一发  阅读(79)  评论(0编辑  收藏  举报