10、11、13位时间戳都适用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../../../view/public/vue/vue.min.js"></script>
</head>
<body>
<div id="app">
{{ time | dateFormat }}
</div>
</body>
<script>
var vm = new Vue({
el: "#app",
data() {
return {
time: 12449158595,
}
},
filters: {
// 时间格式化
dateFormat(key) {
key = key;
const zero = function (value) {
if (value < 10) {
return '0' + value;
}
return value;
};
const myDate = key ? new Date(key) : new Date();
const y = myDate.getFullYear();
const m = zero(myDate.getMonth() + 1);
const d = zero(myDate.getDate());
const hh = zero(myDate.getHours());
const mm = zero(myDate.getMinutes());
const ss = zero(myDate.getSeconds());
//时间格式年月日、时分秒
return `${y}年${m}月${d} ${hh}:${mm}:${ss}`;
}
},
created() {},
mounted() {},
methods: {},
});
</script>
</html>
标签:11,10,13,const,myDate,zero,key,return
From: https://www.cnblogs.com/JaneLifeBlog/p/16620411.html