npm install day.js--save
<template>
<view>
<text>格式化后的日期: {{ formattedDate }}</text>
</view>
</template>
<script>
import dayjs from 'dayjs';
export default {
data() {
return {
timestamp: 1680345600000, // 假设这是后端返回的时间戳(毫秒级)
formattedDate: ''
};
},
onLoad() {
this.formatTimestamp();
},
methods: {
formatTimestamp() {
this.formattedDate = dayjs(this.timestamp).format('YYYY-MM-DD HH:mm:ss');
}
}
};
</script>
<style>
/* 页面样式 */
</style>