easyui列表中的/Date(1352649600000)/时间显示的问题

来源:互联网 发布:淘宝20万店铺数据下载 编辑:程序博客网 时间:2024/06/10 04:57

自从我做完管理系统之后,将做过的难点总结总结,放在这里。这些问题之前都浪费了不少时间,望大家看了之后少走一些弯路。

我们数据库的时间类型是datetime,然后显示在列表里面的时间像/Date(1352649600000)/这样的,是因为json的返回给你的格式就是这种。

这个时候可以在转换器里面写,也可以在视图里面写js,下面我展示一下:

<script>    function ChangeDateFormat(jsondate) {        jsondate = jsondate.replace("/Date(", "").replace(")/", "");//替换
       if (jsondate.indexOf("+") > 0) {            jsondate = jsondate.substring(0, jsondate.indexOf("+"));//截取
      }        else if (jsondate.indexOf("-") > 0) {            jsondate = jsondate.substring(0, jsondate.indexOf("-"));//截取
       }        var date = new Date(parseInt(jsondate, 10));        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;//月份
       var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();//时间
       return date.getFullYear() + "-" + month + "-" + currentDate;//组合起来
 }</script>


然后运行结果就是像 “2015-05-19”一样

0 0