Filter Date Returns NaN-NaN-NaN in AngularJS

The filter created below works in Chrome, but not in Firefox. I do not 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

+6
source share
2 answers

Firefox does not support a date in this format, you first need to replace the slash with a slash.

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

Converting a string to a date may differ from one browser to another. If you get something like NaN in your date, it has to do with date conversion.

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

 moment($scope.date).format("DD/MM/YYYY"); 
0
source

All Articles