您当前的位置: 首页 > 

王佳斌

暂无认证

  • 2浏览

    0关注

    821博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

uview - DatetimePicker 选择器获取时间戳怎么转为日期结果(时间戳转年月日字符串)

王佳斌 发布时间:2022-06-07 13:55:00 ,浏览量:2

前言

TIPS:当前版本为 uview 2.X

当我们使用 DatetimePicker 组件时,@confirm 获取的结果是时间戳,

怎么转为 2022-06-07 这种格式没有相关说明。

在这里插入图片描述

解决方案

使用 uni.$u.timeFormat 方法将时间戳转为正常日期格式即可。

具体代码示例,如下所示。



	
		
	



export default {
	methods: {
		
		/**
		 * 获取选择的日期
		 * @description 将时间戳结果转为年月日字符串
		 * @param {Object} e - 结果
		 * @return void
		 */
		getDate(e) {
			// console.log(e)
			const timeFormat = uni.$u.timeFormat
			console.log(timeFormat(e.value, 'yyyy-mm-dd'))
        	console.log(timeFormat(e.value, 'yyyy-mm-dd hh:MM'))
	        console.log(timeFormat(e.value, 'yyyy-mm'))
		},
		
	}
}

关注
打赏
1665568777
查看更多评论
立即登录/注册

微信扫码登录

0.0408s