Search code examples
angularjsangularjs-directiveangularangularjs-scope

angular date filter no effects


I have date in this format

2016-05-22 08:00:00

I am trying to apply a filter like this

<td>{{ event._source.event_date | date :  "dd.MM.y"}}</td>

but this does notthing. What am I missing?


Solution

  • Angular 1:

    Add following function to your scope to get Date object from your string. First it converts your string with date to format YYYY-MM-DDTHH:MM:SS (adding 'T' between YYYY-MM-DD and HH:MM:SS).

     $scope.isoDate = function(dateString) {
       return new Date(dateString.split(' ').join('T'));
     };
    

    Now you can use it:

    {{ isoDate(event._source.event_date) |  date :  "dd.MM.y" }} 
    

    See jsfiddle