时常会遇到,后端返回的是 时间戳, 需要前端转换为 时间格式。
转换的 methods:
formatDate(now) {
const year = now.getFullYear();
const month = now.getMonth() + 1;
const date = now.getDate();
const hour = now.getHours();
const minute = now.getMinutes();
const second = now.getSeconds();
return `${year}-${month}-${date} ${hour}:${minute}:${second}`;
},
这里面有一个 小坑,是有时候 时间戳需要* 1000; 这个根据后端返回的 格式。
时间戳为10位需*1000,时间戳为13位的话不需乘1000!!!!