zoukankan      html  css  js  c++  java
  • JSON 日期格式问题 /Date(1325696521000)/

    json返回的日期格式/Date(1325696521000)/,怎么办?

    Controller返回的是JsonResult对象就会导致出现这样的格式: /Date(1325696521000)/

    public static JsonResult GetQuery<T>()
    {
        ...
        JsonResult jr = new JsonResult();
        jr.Data = result;
        jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        return jr;
    }

    一种方法是在js里处理:

    return new Date(parseInt(data.substring(6))).toLocaleDateString();//2012年1月5日
    return new Date(parseInt(data.substring(6))).toGMTString();//Wed, 04 Jan 2012 17:02:01 GMT
    return new Date(parseInt(data.substring(6))).toISOString();//2012-01-04T17:02:01.000Z 注意这是1月4日!

    另一种方式是不用JsonResult,而是用Newtonsoft返回string字符串。

    在Controller里:

     public static string GetQuery<T>()
    {
        ...
        return Newtonsoft.Json.JsonConvert.SerializeObject(result);
    }

    这样返回的日期格式是:2012-01-05T01:02:01 注意中间有个 T

    在js里这样处理:

    return data.replace('T', ' ');//2012-01-05 01:02:01
    return data.slice(0, 10);//2012-01-05

    --End--

  • 相关阅读:
    IOS中 init和initialize
    UITableView的常用方法
    加载xib文件的两种方式
    openfire修改服务器名称方法
    POST
    ObjectiveC的动态特性
    枚举 UIButton补充
    深入ObjectiveC的动态特性 Runtime
    IOS中 类扩展 xib
    ObjectiveC语法之代码块(block)的使用
  • 原文地址:https://www.cnblogs.com/ibgo/p/3627846.html
Copyright © 2011-2022 走看看