Adds support for receiving and returning DateOnly/TimeOnly as ISO 8601 string to ASP.NET API
Get it from NuGet
Call UseDateOnlyTimeOnlyStringConverters
on options for AddControllers
and AddJsonOptions
:
builder.Services
.AddControllers(options => options.UseDateOnlyTimeOnlyStringConverters())
.AddJsonOptions(options => options.UseDateOnlyTimeOnlyStringConverters());
After that all DateOnly
and TimeOnly
action arguments will be received and returned as ISO 8601 string.
No additional action is needed.
Install DateOnlyTimeOnly.AspNet.Swashbuckle
package, and add UseDateOnlyTimeOnlyStringConverters
to your swagger configuration:
builder.Services.AddSwaggerGen(c => c.UseDateOnlyTimeOnlyStringConverters());