Change default format for DateTime parsing in ASP.NET Core

前端 未结 10 1043
情话喂你
情话喂你 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:46

    It is better to send your date from front to controller in the ISO format: "yyyy-MM-dd"

    https://www.w3schools.com/js/js_date_formats.asp

    Any server side with any culture will understand this date format correctly.

    So, I'm using sending like this:

    const dateStart = new Date();
    $.post("localhost:4200/start", { dateStart: dateStart.toISOString() },
        function(data) {
            console.log("Started!");
        });
    

提交回复
热议问题