Change default format for DateTime parsing in ASP.NET Core

前端 未结 10 1028
情话喂你
情话喂你 2021-02-02 08:57

I get a Date in an ASP.NET Core Controller like this:

public class MyController:Controller{
    public IActionResult Test(DateTime date) {

    }
}
10条回答
  •  孤城傲影
    2021-02-02 10:00

    I wanted to format the dates in my responses and I did the following in ConfigureServices method:

    services.AddMvc()
    .AddJsonOptions(options =>
    {
        options.SerializerSettings.DateFormatString = "mm/dd/yy, ffffdd";
    });
    

    Hope that helps.

提交回复
热议问题