zoukankan      html  css  js  c++  java
  • JSON日期格式解决方案

    如果Json返回的日期格式是:/Date(1199116800000)/  这种形式,其原因是服务器端使用的数据类型为DateTime类型,如果使用String类型则是正常的时间格式,

    当然也可以在JS中处理,方法有挺多种,例如:


    <script language="javascript" type="text/javascript">   

    $(function () {
                var date= "/Date(1199116800000)/";
                alert(DateFormat(date)); //调用
            });

            function DateFormat(value) {
                var date = new Date(parseInt(value.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;
            }
        </script>


    其实只是取整数部部分,如:/Date(1199116800000)/  取  1199116800000  ,然后使用 var date = new Date(1199116800000) ;

    然后date.Month() 之后就是拼字符串了。

  • 相关阅读:
    【JZOJ 4274】【NOIP2015模拟10.28B组】终章-剑之魂
    【JZOJ 4281】【NOIP2015模拟10.29A组】三色树
    【Luogu P2824】[HEOI2016/TJOI2016]排序
    【Luogu P5490】【模板】扫描线
    【Luogu P2502】[HAOI2006]旅行
    【Luogu P1629】 邮递员送信
    【Luogu P4047】[JSOI2010]部落划分
    【Luogu P4071】[SDOI2016]排列计数
    【Luogu P2508】 [HAOI2008]圆上的整点
    【Luogu P1102】A-B 数对
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2447029.html
Copyright © 2011-2022 走看看