Angular.js format date from json object
I actually combined the answers from @Charminbear and @Nikos ending up in this filter which works quite nice and is quite clear without the regex:
myApp.filter("jsDate", function () { return function (x) { return new Date(parseInt(x.substr(6))); };});
This makes it possible to write
{{ $scope.item.CreatedOn | jsDate | date:"yyyy-MM-dd" }}
One option is to write another filter and put it in the chain. E.g.:
app.filter("mydate", function() { var re = /\/Date\(([0-9]*)\)\//; return function(x) { var m = x.match(re); if( m ) return new Date(parseInt(m[1])); else return null; };});
Basically it uses the regular expression to parse the string and make a Date
(if the format is different than the one shown, you will have to tweak the regular expression).
Use it as:
<td>{{item.CreatedOn | mydate | date: 'yyyy-MM-dd HH:mm'}}</td>
I know I'm late for the party. But I want to tell what helped me was :-
<td>{{item.yourdatefield.slice(6,-2) | date:'dd-MMM-yyyy' }}</td>
Hope it'll help lazy coders like Me. :)