<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>
目前页面显示为时间戳格式。
请问大神们如何将这个时间戳格式化成年月日的格式。
网友回复
启年网络:
最好是用wxs
可以看我写的这篇文章
https://developers.weixin.qq.com/community/develop/article/doc/000442c4a2c63809ac4f74cda56013
LUL:
简单点的就是写个转换函数,如果使用场景多,就作为单独的文件引用。
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('')}`
};