Using AngularJS date filter with UTC date

后端 未结 10 2289
無奈伤痛
無奈伤痛 2020-11-28 07:35

I have an UTC date in milliseconds which I am passing to Angular\'s date filter for human formatting.

{{someDate | date:\'d MMMM yyyy\'}}

A

10条回答
  •  天命终不由人
    2020-11-28 07:40

    Could it work declaring the filter the following way?

       app.filter('dateUTC', function ($filter) {
    
           return function (input, format) {
               if (!angular.isDefined(format)) {
                   format = 'dd/MM/yyyy';
               }
    
               var date = new Date(input);
    
               return $filter('date')(date.toISOString().slice(0, 23), format);
    
           };
        });
    

提交回复
热议问题