小程序
小游戏
企业微信
微信支付
扫描小程序码分享
<block wx:if="{{data.rate.createtime}}"> <view class="info-content data-v-52157f4e"> <view class="u-m-l-10 u-m-r-10 propose data-v-52157f4e">日期:{{data.rate.createtime}}</view> </view> </block>
目前页面显示为时间戳格式。
请问大神们如何将这个时间戳格式化成年月日的格式。
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
最好是用wxs
可以看我写的这篇文章
https://developers.weixin.qq.com/community/develop/article/doc/000442c4a2c63809ac4f74cda56013
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
简单点的就是写个转换函数,如果使用场景多,就作为单独的文件引用。
const formatTime = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}` }; //格式化日期 const formatDate = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() return `${[year, month, day].map(formatNumber).join('-')}` }; //格式化日期 6月1日 const formatSimpleDate = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() return `${[month, day].map(formatNumber).join('.')}` }; // 生成当前日期字符串,精确到秒 const formatTimeSecond = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day,hour, minute, second].map(formatNumber).join('')}` };
https://dayjs.gitee.io/zh-CN/
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
最好是用wxs
可以看我写的这篇文章
https://developers.weixin.qq.com/community/develop/article/doc/000442c4a2c63809ac4f74cda56013
简单点的就是写个转换函数,如果使用场景多,就作为单独的文件引用。
const formatTime = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day].map(formatNumber).join('-')} ${[hour, minute, second].map(formatNumber).join(':')}` }; //格式化日期 const formatDate = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() return `${[year, month, day].map(formatNumber).join('-')}` }; //格式化日期 6月1日 const formatSimpleDate = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() return `${[month, day].map(formatNumber).join('.')}` }; // 生成当前日期字符串,精确到秒 const formatTimeSecond = date => { var date = new Date(date); const year = date.getFullYear() const month = date.getMonth() + 1 const day = date.getDate() const hour = date.getHours() const minute = date.getMinutes() const second = date.getSeconds() return `${[year, month, day,hour, minute, second].map(formatNumber).join('')}` };
https://dayjs.gitee.io/zh-CN/