zoukankan      html  css  js  c++  java
  • .net webapi返回时间类型带字母T,不同平台解析显示时间有误

    分析:

    1,SQL server数据库默认是DateTime类型,不可能每个接口都转成String

    2,.net webapi 设置webapiconfig.cs

    3,写个通用返回结果对象方法(默认只有查询接口用到,删除修改新增是存储不需要处理)

    一,在webapiconfig.cs添加如下代码

    //望高手添加具体说明,本人搞不懂具体啥意思
    public static void Register(HttpConfiguration config)
            { 
              ReturnJsonSerializerSettings();
    
            }
    
    private static void ReturnJsonSerializerSettings()
            {
                var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
                json.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
                json.SerializerSettings.DateFormatString = "yyyy'-'MM'-'dd' 'HH':'mm':'ss";
                json.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
            }

    二,接口返回Json对象时方法进行重构

      a)Json 默认有3个方法带不同参数

    return Json(new AjaxResult { type = ResultType.success, message = message, resultdata = data },GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);

    注意:只有调用方法输入了

    GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings 才能呈现出不带T的字母,同时只用改这个Json方法。
  • 相关阅读:
    String驻留带来的危害
    Go语言的堆栈分析
    SecureCRT使用技巧
    Javascript中相同Function使用多个名称
    记录Office Add-in开发经验
    Silverlight和WPF中DataContractJsonSerializer对时间的处理差异
    ASP.NET MVC项目实践技巧
    有点担心Node.js的未来了
    回首经典的SQL Server 2005
    duilib关于学习Demo中的QQ
  • 原文地址:https://www.cnblogs.com/qingjiawen/p/14066470.html
Copyright © 2011-2022 走看看