Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 筛选日期返回AngularJS中的NaN_Javascript_Angularjs_Filter_Angularjs Scope - Fatal编程技术网

Javascript 筛选日期返回AngularJS中的NaN

Javascript 筛选日期返回AngularJS中的NaN,javascript,angularjs,filter,angularjs-scope,Javascript,Angularjs,Filter,Angularjs Scope,我在下面创建的过滤器适用于Chrome,但不适用于Firefox。我不明白为什么 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);

我在下面创建的过滤器适用于Chrome,但不适用于Firefox。我不明白为什么

  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> 
{{project.date_created_at|dateCustom}

火狐


Firefox不支持该格式的日期,您必须先用斜杠替换破折号

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

将字符串转换为日期可能因浏览器而异。如果你在约会中得到类似于
NaN
的东西,那是因为日期转换

我发现最好的方法是使用一个很好的工具来设置日期。在我使用它之后,它在每个浏览器中都能有效地工作。仅使用:

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

输入值是多少?请检查我的更新。我仍然没有看到值,只是对象项目。创建日期\u没有给我们任何关于其中内容的线索。几乎完美!你错过了一个
。非常感谢。是的,很抱歉,我的快速复制/粘贴失败。我已经更新了答案。