zoukankan      html  css  js  c++  java
  • 微信小程序json时间格式化处理

    //打开微信小程序后,部分模板绑定数据是通过接口调取的,当遇到数据的时间被json格式化后,需要正常的显示。可以通过扩展一个方法去处理时间。
    1.打开utils里的utils.js  ,也可以按照自己的习惯添加我们需要扩展的函数renderTime,方法如下
    function renderTime(date) {
           var da = new Date(parseInt(date.replace("/Date(", "").replace(")/", "").split("+")[0]));
           var  Year = da.getFullYear(); //ie火狐下都可以
              var  Month = da.getMonth() + 1;
              var  Day = da.getDate();
              var  Hours=da.getHours();
              var  Minutes=da.getMinutes();
              var  Seconds=da.getSeconds();
                var CurrentDate = "";
                CurrentDate += Year + "-";
                if (Month >= 10) {
                    CurrentDate += Month + "-";
                }
                else {
                    CurrentDate += "0" + Month + "-";
                }
                if (Day >= 10) {
                    CurrentDate += Day;
                }
                else {
                    CurrentDate += "0" + Day;
                }
                if (Hours <10) {
                     Hours = "0" + Hours;
                }
                if (Minutes < 10) {
                    Minutes ="0"+ Minutes;
                }
                if (Seconds < 10) {
                      Seconds ="0"+ Seconds;
                }
                return CurrentDate + " " + Hours + ":" + Minutes + ":" + Seconds;
      }
    //引用的话,只需要在你的页面下的js里
    var util = require('../../utils/util.js');   你放置这个函数。
    当然,utils里的
    //扩展的方法需要在Module里去声明
    module.exports = {
      renderTime:renderTime
    }
    调用方法。便是  util.renderTime(date);即可。
    岁月是把杀猪刀,不依不饶。
  • 相关阅读:
    LCA问题第二弹
    LCA问题
    树状数组(Binary Indexed Tree,BIT)
    线段树第二弹(区间更新)
    线段树+RMQ问题第二弹
    RMQ问题第一弹
    分治法二(平面最近点对)
    分治法(一)
    带权并查集
    提交一个变量或数组到另一个jsp页面
  • 原文地址:https://www.cnblogs.com/qh1688/p/6524304.html
Copyright © 2011-2022 走看看