vue+elementUI 时间戳格式转换

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_40578880/article/details/82014950

时间戳13位数。10位数的时间戳应该 *1000
methods:
//时间戳转换

    formatDate(row, column) {
                let date = new Date(parseInt(row.subscribeTime) * 1000);
                let Y = date.getFullYear() + '-';
                let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-';
                let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' ';
                let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':';
                let m = date.getMinutes()  < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':';
                let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
                return Y + M + D + h + m + s;
            },

样式中:

<el-table-column
    label="关注时间"
     prop="subscribeTime"
      :formatter="formatDate"
  >

1533014442 转化为2018-07-31 13:20:42

猜你喜欢

转载自blog.csdn.net/weixin_40578880/article/details/82014950
今日推荐