时间戳转时间
utils页面
javascript
function timestampToTime(time) {
const date = new Date(time);
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0'); // 月份从0开始,所以要加1,并补齐0
const day = String(date.getDate()).padStart(2, '0'); // 补齐日期
const hours = String(date.getHours()).padStart(2, '0'); // 补齐小时
const minutes = String(date.getMinutes()).padStart(2, '0'); // 补齐分钟
const seconds = String(date.getSeconds()).padStart(2, '0'); // 补齐秒
const convertedTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
return convertedTime;
}
使用页面
javascript
<view class="content" v-for="item in refuelList" :key="item.id" @click="detail(item.id)">
<view class="payTime">
{{dataFormat(item.tranTime)||'-'}}
</view>
</view>
// 时间戳转时间
dataFormat(time) {
if (!time) {
return null
}
return this.$utils.timestampToTime(time)
},