uniapp时间戳转时间

时间戳转时间

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)
	},
相关推荐
二十雨辰5 小时前
[uni-app]小兔鲜-07订单+支付
uni-app
工业互联网专业9 小时前
毕业设计选题:基于ssm+vue+uniapp的校园水电费管理小程序
vue.js·小程序·uni-app·毕业设计·ssm·源码·课程设计
以对_17 小时前
uview表单校验不生效问题
前端·uni-app
小雨cc5566ru1 天前
uniapp+Android面向网络学习的时间管理工具软件 微信小程序
android·微信小程序·uni-app
二十雨辰1 天前
[uni-app]小兔鲜-04推荐+分类+详情
前端·javascript·uni-app
小雨cc5566ru2 天前
hbuilderx+uniapp+Android健身房管理系统 微信小程序z488g
android·微信小程序·uni-app
敲啊敲95272 天前
uni-app之旅-day02-分类页面
前端·javascript·uni-app
二十雨辰2 天前
[uni-app]小兔鲜-06地址+sku+购物车
前端·javascript·vue.js·uni-app
康康爹2 天前
uniapp 小程序,登录上传头像昵称页面处理步骤
小程序·uni-app
小雨cc5566ru2 天前
微信小程序hbuilderx+uniapp+Android 新农村综合风貌旅游展示平台
android·微信小程序·uni-app