Does anyone know how to configure MVC6's json output to default to a ISO UTC DateTime string format when returning DateTime objects?
In WebApi2 I could set the JsonFormatter SerializerSettings and convert datetimes however i'm a bit stuck with how to do this in MVC6
And I just stumbled onto something that helped me figure it out.
Just in case anyone wants to know
In your Startup.ConfigureServices
services.AddMvc().AddJsonOptions(options =>
{
options.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc;
});
来源:https://stackoverflow.com/questions/41728737/iso-utc-datetime-format-as-default-json-output-format-in-mvc-6-api-response