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() 之后就是拼字符串了。

  • 相关阅读:
    使用BeyondCompare作为Subversive的比较器
    Ubuntu下安装jdk6的方法和步骤
    推荐几款通用的数据库管理工具
    通用数据库都有哪些
    Linux下卸载ORACLE的多种方法(参考使用)
    jar包查询网站 非常好用!
    8种Nosql数据库系统对比
    SQL2005数据库镜像的步骤
    建立与删除SQL 2008事务复制发布
    同步复制JOB说明
  • 原文地址:https://www.cnblogs.com/zhuiyi/p/2447029.html
Copyright © 2011-2022 走看看