小程序页面处理后台返回时间格式
后台返回格式:“2020-12-24 00:00:00”
我们想要格式: “2020-12-24”
首先在utils文件夹下创建filter.wxs文件
//通过substring截取处理时间
function newFormatTime(timestamp) {
return (timestamp.substring(0, 10))
}
module.exports = {
newFormatTime:newFormatTime
}
在需要渲染的页面引入filter.wxs文件
<wxs module="filter" src='../../utils/filter.wxs'></wxs>//引入
//使用
<view class="two">{{filter.newFormatTime(item.productionCycleStart)}}</view>
//item.productionCycleStart要渲染的数据
//newFormatTime方法名