zoukankan      html  css  js  c++  java
  • 小程序对mongodb日期显示处理问题

    描述:微信小程序开发后端数据库使用的是mongodb。其中有个字段为日期类型,这样在查询数据显示的时候如下:/Date(1584538219495)/   为了能够正常的显示日期需要使用js处理一下。

    js函数

      //处理日期
      changeDateFormat: function (cellval){
        var dateVal = cellval + "";
        if (cellval != null) {
          var date = new Date(parseInt(dateVal.replace("/Date(", "").replace(")/", ""), 10));
          var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
          var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    
          var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
          var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
          var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    
          return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
        }
      },

    调用:

        // var dd = "/Date(1584538219495)/"
        // var mm = this.changeDateFormat(dd);
        // console.log(mm);

     在这里遍历数组,对里面的日期字段进行处理。处理之后就可以正常显示了。

  • 相关阅读:
    171. Excel Sheet Column Number (Easy)
    349. Intersection of Two Arrays (Easy)
    453. Minimum Moves to Equal Array Elements (Easy)
    657. Judge Route Circle (Easy)
    CSS笔记
    保存页面状态
    UI开发总结
    ubuntu 下配置munin
    反向代理配置
    JavaScript 高级程序设计第二版
  • 原文地址:https://www.cnblogs.com/xubao/p/12520911.html
Copyright © 2011-2022 走看看