微信小程序 WXS时间戳处理

微信小程序 wxs时间戳处理

看了几篇关于wxs时间戳处理的博客,但是代码处理得到的时间都是1970年,但是也了解到一些信息,索性改了下js代码,然后运行成功:

wxs 获取当前日期没法使用new Date,但可以用Date() 代替。

wxs代码:

var timeTranslate = {
    //时间戳转换
  timestampToTime: function (timestamp) {
    console.log(timestamp)
    var date = getDate(timestamp * 1000);//时间戳为10位需*1000
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = date.getDate() + ' ';
    var h = date.getHours() + ':';
    var m = date.getMinutes() + ':';
    var s = date.getSeconds();
    return Y + M + D + h + m + s;
  }
}
module.exports = {
  timestampToTime: timeTranslate.timestampToTime
}

wxml代码:


{{timeTranslate.timestampToTime(detail.createTime)}}

参考:
https://www.cnblogs.com/crf-Aaron/archive/2017/11/16/7844462.html

你可能感兴趣的:(微信小程序)