此篇专用于我平时遇到的时间格式转化问题,因查找不到出处,所以此处暂为原创,若有更改需要请联系。
时间戳格式转化为yy-mm-dd hh-mm-ss
formatTime(value) {
// 时间戳为10位需*1000,时间戳为13位的话不需乘1000
const date = new Date(value*1000);
const Y = date.getFullYear() + '-';
const M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
const D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate() + ' ';
const h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
const m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
const s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();
return Y + M + D + h + m + s;
},