Correctly format ASP.NET MVC dates for AngularJS

前端 未结 4 1576
灰色年华
灰色年华 2021-01-05 23:51

I am using AngularJS to get data from an ASP.NET server application and display it on the client side. Here is what I\'m getting:



        
4条回答
  •  余生分开走
    2021-01-06 00:29

    Create custom filter as below:

    app.filter("dateFilter", function () {
        return function (item) {
            if (item != null) {
                return new Date(parseInt(item.substr(6)));
            }
            return "";
        };
    });
    

    You can then apply the filter in your HTML

    
    {{team.CreatedOn | dateFilter | date:"dd-MM-yyyy"}}
    

    Hope it helps.

提交回复
热议问题