web API datetime format

I have a Winform client that sends a json post request to my controller with a datetime value of the format dd/MM/yyyy and the call returns a status code 400.

I tried to add:

<globalization uiCulture="fr" culture="fr-FR" />

to my web.config file but it’s still not working.

I should add also That I have no control over the client and that I added:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/mm/yyyy}")]

to my model with no result


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There’s a pretty simple solution. Just add the CultureInfo to the JsonSerializerSettings in global.asax, method Application_Start().

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = 
    new JsonSerializerSettings
        DateFormatHandling = DateFormatHandling.IsoDateFormat,                           
        DateTimeZoneHandling = DateTimeZoneHandling.Unspecified,
        Culture = CultureInfo.GetCultureInfo("fr-FR")

Method 2

If you are posting this via JSON then you should be able to create a JSON.NET converter for your date format.

In fact in researching this answer I found this full example on SO WebApi Json.NET custom date handling

Obviously just alter the conversion in MyDateTimeConvertor to be something that uses the current culture and the format you spefified.

DateTime.ParseExact(reader.Value.ToString(), "dd/mm/yyyy", CultureInfo.CurrentCulture);


Method 3


"AccessStartTime": "2020-12-01T00:00:00",

add below code into Application_Start() of Global.asax.cs
      IsoDateTimeConverter converter = new IsoDateTimeConverter
            DateTimeStyles = DateTimeStyles.AdjustToUniversal,
            DateTimeFormat = "yyyy-MM-dd HH:mm:ss"

 "AccessStartTime": "2020-12-01 00:00:00",


All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x