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)
	},
相关推荐
ResponseState2001 小时前
安卓原生写uniapp插件手把手教学调试、打包、发布。
前端·uni-app
h_65432103 小时前
uniapp app端解析图片的经纬度、方位角
uni-app
h_65432103 小时前
uniapp app端获取指定路径下的所有图片
uni-app
雪芽蓝域zzs3 小时前
uniapp真机运行鸿蒙定位报getLocation:fail maybe not obtain GPS Permission
华为·uni-app·harmonyos
初遇你时动了情3 小时前
不用每个请求都写获取请求 类似无感刷新逻辑 uniapp vue3 react实现方案
javascript·react.js·uni-app
apollo_qwe21 小时前
解决移动端键盘遮挡痛点
uni-app
脾气有点小暴2 天前
scroll-view分页加载
前端·javascript·uni-app
脾气有点小暴2 天前
uniapp自定义头部导航
前端·uni-app
前端 贾公子2 天前
[uniapp][swtich开关]阻止切换状态(类似阻止事件冒泡)
uni-app
雪芽蓝域zzs2 天前
uniapp基于picker选择器实现年月日时分秒
uni-app