码迷,mamicode.com
首页 > 其他好文 > 详细

时间戳转换时间格式

时间:2019-02-14 17:46:55      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:type   token   cti   ati   通过   return   form   dex   date   

<!-- 时间戳 -->
<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;
  },
})

 

时间戳转换时间格式

标签:type   token   cti   ati   通过   return   form   dex   date   

原文地址:https://www.cnblogs.com/xiaoxiao2017/p/10375814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!