微信小程序列表时间戳转换
标签:小程序 this 转换 bsp 引入 get 技术 exports src
第一步先写js 随便命名为times.js
function toDate(number){
var n=number * 1000;
var date = new Date(n);
var Y = date.getFullYear() ‘/‘;
var M = (date.getMonth() 1 < 10 ? ‘0‘ (date.getMonth() 1) : date.getMonth() 1) ‘/‘;
var D = date.getDate()<10 ? ‘0‘ date.getDate() : date.getDate();
return (Y M D)
}
module.exports = {
toDate: toDate
}
第二步,在需要转换的js文件中
2.1引入
var times = require(‘../../utils/times.js‘);
2.2测试数据
2.3逻辑代码,因为是测试数据,没有请求后台数据
onLoad: function (options) {
var that = this //很重要,一定要写
console.log(that.data.lists)
for(var i=0;i<that.data.lists.length;i ){
that.data.lists[i]["times"] = times.toDate(that.data.lists[i]["times"])
}
that.setData({
lists:that.data.lists
})
},
2.4页面层渲染
2.5最后,大功告成,效果如下:
微信小程序列表时间戳转换
标签:小程序 this 转换 bsp 引入 get 技术 exports src
温馨提示: 本文由杰米博客推荐,转载请保留链接: https://www.jmwww.net/weixin/16007.html
- 上一篇:原生小程序底部弹出层动画过渡
- 下一篇:微信小程序iOS下拉白屏晃动,坑坑坑