ASP.NET WebAPI 接收参数时,时间类型(UTC)少8小时或者将UTC转本地时间(LocalTime)解决方式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011508145/article/details/79992242
直接切入问题:UI及前端传递的时间参数为:2000-06-26T16:00:00Z

在Controller中如果请求的参数类型为时间类型的话,DateTime.Kind会是UTC,中国地区的会减少8个小时,所以需要调整一下WebApiConfig,将其设置为Local本地时间
WebApiConfig添加:

var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
            json.Indent = false;
            json.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;


猜你喜欢

转载自blog.csdn.net/u011508145/article/details/79992242