Dates without time in ASP.NET Web API's JSON output

前端 未结 3 671
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 18:12

Is there a simple way to configure JSON.NET so that some DateTime fields will be formatted without time and other DateTime fields

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-01 18:18

    Try adding this line to configure your Web API:

    config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
        new IsoDateTimeConverter() { DateTimeFormat = "yyyy-MM-dd" });
    

提交回复
热议问题