vue 时间戳的转化
main.js 配置全局:
Vue.filter('formatTimestamp', function (timestamp) {
if (!timestamp) return ''
let date
if(timestamp.toString().length == 10) {
date = new Date(timestamp * 1000); // 将秒转换为毫秒
} else {
date = new Date(timestamp); // 毫秒级不用转换
}
const year = date.getFullYear();
const month = ('0' + (date.getMonth() + 1)).slice(-2); // 月份是从0开始的
const day = ('0' + date.getDate()).slice(-2);
const hours = ('0' + date.getHours()).slice(-2);
const minutes = ('0' + date.getMinutes()).slice(-2);
const seconds = ('0' + date.getSeconds()).slice(-2);
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
})

浙公网安备 33010602011771号