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
In case you've migrated to ASP.NET Core 3.0 the code that sf. has posted doesn't work anymore. To spare you some of my headache, here is what you need to do. First create a custom DateTime JSON converter:
And then use it in your
Startup.cs
as follows:I hope this helps someone.