Asp.net web API datetime format

前端 未结 2 975
孤街浪徒
孤街浪徒 2020-12-18 11:27

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 trie

2条回答
  •  我在风中等你
    2020-12-18 12:14

    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")
        };
    

提交回复
热议问题