ASP.NET MVC JsonResult Date Format

前端 未结 25 3329
渐次进展
渐次进展 2020-11-21 11:22

I have a controller action that effectively simply returns a JsonResult of my model. So, in my method I have something like the following:

return new JsonRes         


        
25条回答
  •  旧时难觅i
    2020-11-21 11:42

    The better way to handle dates in knockoutjs is to use moment library and handle dates like boss. You can easily deal with dates like /Date(-62135578800000)/. No need to bother of how your serialize date in controller.

    function jsonToDate(date,format) {
       return moment(date).format(format);
    }
    

    use it like

    var formattedDate = jsonToDate(date,'MM/DD/YYYY')
    

    momentjs supports lots of date time formats and utility functions on dates.

提交回复
热议问题