How to create a custom filter that formats a date in angularJS

<div ng-app="filterApp" ng-controller="FilterController">
    <p>Original Date: {{ currentDate }}</p>
    <p>Formatted Date: {{ currentDate | customDateFilter }}</p>
</div>

<script>
    var app = angular.module('filterApp', []);
    app.controller('FilterController', function($scope) {
        $scope.currentDate = new Date();
    });

    app.filter('customDateFilter', function($filter) {
        return function(input) {
            return $filter('date')(input, 'yyyy-MM-dd HH:mm:ss');
        };
    });
</script>

 

Post your Answer