Вопрос

The filter I created below works on Chrome but not Firefox. I don't understand why.

  myApp.filter('dateCustom', [ '$filter', function ($filter) {
    return function (input) {

      // input => 2014-05-13 15:04:48 

      if(angular.isDefined(input)){
        var d = new Date(input);
        var time = d.getTime();
        return $filter('date')(time,'dd/MM/yyyy');
      }
    }
  }]);

HTML :

<span> {{ project.date_created_at | dateCustom }} </span> 

Chrome

enter image description here

Firefox

enter image description here

Это было полезно?

Решение

Firefox doesn't support a date in that format, you will have to replace the dash's with slashes first.

var d = new Date(input.replace(/-/g, '/'));

Другие советы

Converting a string to date may vary from one browser to another. If you are getting something like NaN on your date's it is because of the Date conversion.

The best way I found is to use MomentJS, a great tool to formating dates. Effectively after I used it worked in every browser. Just using:

moment($scope.date).format("DD/MM/YYYY");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top