问题描述
其实网上已经有很多说的了,都是再WebApiConfig添加关于时间的配置
下面是代码
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
new Newtonsoft.Json.Converters.IsoDateTimeConverter()
{
DateTimeFormat = "yyyy-MM-dd hh:mm:ss"
}
);
或者
//格式化json数据中的时间的T
var jsontimeset = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings;
jsontimeset.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
jsontimeset.DateFormatString = "yyyy-MM-dd HH:mm:ss";
上面的方法都行
但是他们就是没说最重要的,得引用这个配置才行啊
Json(new { total = total, rows = rows }, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);
看效果
另外,用的是postman