今天就跟大家聊聊有關(guān)怎么在微信小程序中將列表轉(zhuǎn)換成時間戳,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結(jié)了以下內(nèi)容,希望大家根據(jù)這篇文章可以有所收獲。

第一步先寫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
}第二步,在需要轉(zhuǎn)換的js文件中
引入
var times = require('../../utils/times.js');測試數(shù)據(jù)

邏輯代碼,因?yàn)槭菧y試數(shù)據(jù),沒有請求后臺數(shù)據(jù)
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
})
},頁面層渲染

最后,大功告成,效果如下:

看完上述內(nèi)容,你們對怎么在微信小程序中將列表轉(zhuǎn)換成時間戳有進(jìn)一步的了解嗎?如果還想了解更多知識或者相關(guān)內(nèi)容,請關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝大家的支持。
網(wǎng)站名稱:怎么在微信小程序中將列表轉(zhuǎn)換成時間戳-創(chuàng)新互聯(lián)
文章鏈接:http://chinadenli.net/article24/dijjje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站營銷、用戶體驗(yàn)、移動網(wǎng)站建設(shè)、定制網(wǎng)站、網(wǎng)站設(shè)計(jì)、搜索引擎優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容