I know there are lots of topics talking about how to properly configure the culture and I see other people having the issue of wrong Date formatting in api requests.
In Germany we have the following format for dates: dd.MM.yyyy
.
This is the request I am sending to my api:
http://localhost:1111/api/Test/Test?datum=07.08.2019
However, the request received inside the controller always displays it like this: 08.07.2019. As you can see the day and month are swapped for some reason.
This is my startup.cs
:
public void ConfigureServices() {
...
services
.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
// Maintain property names during serialization. See:
// https://github.com/aspnet/Announcements/issues/194
.AddJsonOptions(options =>
{
options.SerializerSettings.Culture = new CultureInfo("de-DE");
options.SerializerSettings.ContractResolver = new DefaultContractResolver();
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
var cultureInfo = new CultureInfo("de-DE");
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;
}
I am getting very frustrated with this issue and I can't seem to solve it. I know that I can just send the string ISO formatted but this should not be the ideal solution. Please don't show me any workarounds, I am interested in the proper solution and why it isn't working.
I want to send my date in the format dd.MM.yyyy