获取最近更新时间,并将其格式化
<script>
export default {
data(){return { lastUpdatedTime: "2023-08-26 09:53:23", // 最近更新时间}},
methods:{
getLastUpdateTime() {
var nowTime = new Date();
var year = nowTime.getFullYear();
var month = ("0" + (nowTime.getMonth() + 1)).slice(-2);
var day = ("0" + nowTime.getDate()).slice(-2);
var hours = ("0" + nowTime.getHours()).slice(-2);
var minutes = ("0" + nowTime.getMinutes()).slice(-2);
var seconds = ("0" + nowTime.getSeconds()).slice(-2);
// 中间变量
this.lastUpdatedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
},
}
}
</script>