zoukankan      html  css  js  c++  java
  • 前台Json格式中时间的格式转换

     后台序列化成Json格式之后,传到前台的时间格式为:”/Date(1431069217610+0800)/”;

     前台处理:

     1  // json时间格式化
     2         function ChangeDateFormat(jsondate) {
     3             jsondate = jsondate.replace("/Date(", "").replace(")/", "");
     4             if (jsondate.indexOf("+") > 0) {
     5                 jsondate = jsondate.substring(0, jsondate.indexOf("+"));
     6             }
     7             else if (jsondate.indexOf("-") > 0) {
     8                 jsondate = jsondate.substring(0, jsondate.indexOf("-"));
     9             }
    10             var date = new Date(parseInt(jsondate, 10));
    11             var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    12             var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    13             var hours = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
    14             var minutes = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
    15             var seconds = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
    16             return date.getFullYear() + "-" + month + "-" + currentDate + " " + hours + ":" + minutes + ":" + seconds;
    17         }

    转换之后的结果:2015-05-08 15:13:37

  • 相关阅读:
    【干货】和你谈谈数据分析报告
    输入整型数组和排序标识
    删除字符串中出现次数最少的字符
    字符串排序
    老男孩Django笔记(非原创)
    Cloakroom
    星际网络
    乘车路线
    渔民的烦恼
    【教程】Microsoft Wi-Fi Direct Virtual关闭方法
  • 原文地址:https://www.cnblogs.com/Yunshine-sina/p/4533928.html
Copyright © 2011-2022 走看看