Change default format for DateTime parsing in ASP.NET Core

前端 未结 10 1026
情话喂你
情话喂你 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 09:40

    DateTime dt = DateTime.ParseExact(dateString, "ddMMyyyy", CultureInfo.InvariantCulture);
    dt.ToString("yyyyMMdd");
    

    As per https://stackoverflow.com/a/3477821/2914174

提交回复
热议问题