<!-- 时间戳 --> <view>{{create_time0}}</view> <!-- 转化的时间格式 --> <view>{{create_time}}</view>
Page({ // 注:1:formatDate 2.zeroize 3.通过接口拿到时间戳 data: { create_time: ‘‘, pay_time: ‘‘ }, onLoad: function (options) { var that = this; var that = this var data = { token: "112e309263e37a51a4cd7c98cf681165", id: 1, } console.log(JSON.stringify(data)) wx.request({ url: "https://www.xiaojingxiche.com/index.php/Api/Order/orderDetails", data: data, header: { ‘content-type‘: ‘application/x-www-form-urlencoded‘ }, method: ‘POST‘, success: function (res) { console.log(JSON.stringify(res)) if (res.data.code == 1) { that.setData({ create_time0: res.data.data.create_time,// 获取到的时间戳 create_time: that.formatDate(res.data.data.create_time), // 获取到的时间戳 引用转换时间格式 }) } }, }) }, // 时间戳转换格式必备1 formatDate: function (now) { var that = this var now = new Date(now * 1000); var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); return year + "-" + that.zeroize(month) + "-" + that.zeroize(date) + " " + that.zeroize(hour) + ":" + that.zeroize(minute) + ":" + that.zeroize(second); }, // 时间戳转换格式必备2 zeroize: function (num) { var that = this return (String(num).length == 1 ? ‘0‘ : ‘‘) + num; }, })
原文地址:https://www.cnblogs.com/xiaoxiao2017/p/10375814.html
时间: 2024-11-10 12:04:14