The first step is to write js casually named 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
}
The second step, js files need to be converted in
2.1 introduces
var times = require('../../utils/times.js');
2.2 Test Data
2.3 the logic code, because the test data, the background data is not requested
onLoad: function (options) {
var that = this // is very important, be sure to write
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 page rendering layer
2.5 Finally, done, the effect is as follows: