Search code examples
javascriptangularjsangular-filters

Date format filter is not working angular js


I am new to angular js . I am trying to give some date format like Nov-24-2016, but its not working at all . Below is my code.

{{ x.created | date:" MM-d-y" }}

Here I want this format Nov-24-2016

and x.created value = 2016-11-24 08:02:21

Any suggestion? Thank you


Solution

  • you can create a custom

    .filter('datetime', function($filter){
        return function(input){
          if(input == null){ return ""; } 
    
          var _date = $filter('date')(new Date(input),'MM-dd-yyyy');         
          return _date.toUpperCase();
    
        };
    });
    
    
    {{ x.created | datetime }}