Asp.net web API datetime format

前端 未结 2 958
孤街浪徒
孤街浪徒 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 11:49

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

    AND

    writer.WriteValue(((DateTime)value).ToString("dd/mm/yyyy"));
    

提交回复
热议问题