Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

filter date returns NaN-NaN-NaN in AngularJS

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

like image 725
Steffi Avatar asked May 13 '14 13:05

Steffi


1 Answers

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, '/'));
like image 167
Mathew Berg Avatar answered Oct 22 '22 10:10

Mathew Berg