Set an AngularJS date filter format to be used by all references to the date filter?

前端 未结 5 966
余生分开走
余生分开走 2021-02-18 18:03

Rather that having to define a custom format for each call to the date filter, is there a way to globally define a default format (other than \'medium\'

5条回答
  •  再見小時候
    2021-02-18 18:24

    Try this

    angular.module('yourmodule').filter('myDate', function($filter)
    {
        return function(input)
        {
            if(input == null){ return ""; }
            var _date = $filter('date')(new Date(input), 'dd MMMM @ HH:mm:ss');
            return _date.toUpperCase();
        };
    });
    

    Html

    {{systemTime | myDate}}
    

    Date filtering and formatting in Angular js.

提交回复
热议问题