zoukankan      html  css  js  c++  java
  • 时间戳转换时间格式

    <!-- 时间戳 -->
    <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;
      },
    })
  • 相关阅读:
    PHP做ERP, CRM, CMS系统需要注意哪些地方
    java封装小实例
    java中数组的数组问题
    switch语句小练习
    java交换两个变量值a,b的多钟方法
    java中 i = i++ 的结果
    每日java基础知识(01)
    计算机存储负数以及int转byte时-128的出现
    python RSA 加密
    CentOS 7 安装 建立svn仓库 远程连接
  • 原文地址:https://www.cnblogs.com/xiaoxiao2017/p/10375814.html
Copyright © 2011-2022 走看看