• 时间戳转换时间格式


    <!-- 时间戳 -->
    <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;
      },
    })
  • 相关阅读:
    STL源代码剖析——STL算法之set集合算法
    iOS + Nodejs SSL/Https双向认证
    C语言将10进制转为2进制
    图的遍历算法
    Web—CSS概述
    苹果新的编程语言 Swift 语言进阶(八)--属性
    UVa 10700
    C++实现KMP模式匹配算法
    软件project
    oralce GROUPING SETS
  • 原文地址:https://www.cnblogs.com/xiaoxiao2017/p/10375814.html
Copyright © 2020-2023  润新知