WebAPI返回时间数据不带T

最近一段时间项目里面使用WebAPI比较多,但是在返回时间数据的时候回默认带上T,就像这样子

"2016-04-21T13:26:17.4701811+08:00"

这样的数据在其他系统解析的时候会出现一些奇葩的问题,而且在调试的时候也不好识别。用百度查了一下,网上给出了如下的解决方案,在App_Start文件夹中的WebApiConfig.cs文件中Register方法中设置全局的Json序列化器时间转换格式,即可去除时间数据中的T。具体代码如下:

            //返回时间不带T
            config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter()
            {
                DateTimeFormat = "yyyy-MM-dd hh:mm:ss"
            });

 优化后的时间数据如下

"2016-04-21 01:39:06"
原文地址:https://www.cnblogs.com/enternal/p/5416585.html