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 小时前
uniapp+firstUI——上传视频组件fui-upload-video
前端·javascript·uni-app
耶啵奶膘18 小时前
uniapp——地图路线绘制map
uni-app
shadouqi19 小时前
uniapp实现图片预览,懒加载,下拉刷新等
uni-app
走,带你去玩20 小时前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
菌菇汤1 天前
uni-app实现单选,多选也能搜索,勾选,选择,回显
前端·javascript·vue.js·微信小程序·uni-app·app
某公司摸鱼前端1 天前
uniapp socket 封装 (可拿去直接用)
前端·javascript·websocket·uni-app
遗憾随她而去.1 天前
uniapp 中使用路由导航守卫,进行登录鉴权
前端·uni-app
牧杉-惊蛰2 天前
uniapp微信小程序css中background-image失效问题
css·微信小程序·uni-app
Little_Code2 天前
uniapp 使用ffmpeg播放rtsp
ffmpeg·uni-app·rtsp
儿歌八万首2 天前
uniapp 和原生插件交互
uni-app·交互