Pass a JSON format DateTime to ASP.NET MVC

后端 未结 3 1655
不知归路
不知归路 2021-02-13 12:17

We know that MVC returns DateTime for JsonResult in this format: /Date(1240718400000)/, and we know how to parse it in JS.

However, It seems that MVC doesn\

3条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-13 13:02

    In your model, use this to parse the date:

    // property
    String CreateDate;
    DateTime CreateDateAsDate;
    
    // drop prefix, drop suffix, parse as long and read as ticks
    CreateDateAsDate date = new DateTime(Int64.Parse(
        CreateDate.Substring(6).Replace(")/",String.Empty)));
    

提交回复
热议问题