小程序循环输出时得时间格式化

mac2024-04-15  41

在相关得js页面

 

 

源码:

/**时间转化 */ getDateStr(seconds) { var date = new Date(seconds) var year = date.getFullYear(); var month = date.getMonth() + 1; var day = date.getDate(); var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(); var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes(); var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds(); var currentTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second; return currentTime },

 

 

userWalletDetails: function () { let that = this; network.userWalletDetails({},res => { if (res.success) { /**时间转化 */ var arr=res.data.rows; for(var i=0;i<arr.length;i++){ console.log(arr[i].createdAt); arr[i].createdAt = that.getDateStr(arr[i].createdAt) } that.setData({ list: res.data.rows }) } else { wx.showToast({ title: res.errorMessage, icon: 'none', duration: 2000 }) } }); },

 

最新回复(0)