.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方法。
原文地址:https://www.cnblogs.com/qingjiawen/p/14066470.html