2017-02-16 26 views
0

我想从我的数据库中使用Angular js格式hr:min:sec显示时间,但在Mozilla和Safari中出现错误NaN hr NaN min NaN它在Chrome中运行良好。这里是我的代码:NaN小时NaN分钟在Mozilla Firefox版本小于45的NaN秒错误

$scope.initTimer = function (id, starttime, endtime) { 
    $scope.data.push({"id": id, "starttime": starttime, "endtime": endtime}); 
    $scope.now = new Date(endtime).getTime(); 
    $scope.callTimer($scope.data); 
}; 
$scope.callTimer = function (data) { 
    angular.forEach(data, function (value) { 
     $scope.enquirytime = new Date(value.starttime).getTime(); 
     $scope.distance = ($scope.enquirytime + (1000 * 60 * 60 * 24)) - $scope.now; 
     $scope.days = Math.floor($scope.distance/(1000 * 60 * 60 * 24)); 
     $scope.hours = Math.floor(($scope.distance % (1000 * 60 * 60 * 24))/(1000 * 60 * 60)); 
     $scope.minutes = Math.floor(($scope.distance % (1000 * 60 * 60))/(1000 * 60)); 
     $scope.seconds = Math.floor(($scope.distance % (1000 * 60))/1000); 
     $scope.showtime[value.id] = $scope.hours + " hr " + $scope.minutes + " min " + $scope.seconds + " sec "; 
     if ($scope.distance < 0) { 
      $scope.hideenquiry[value.id] = true; 
     } 
    }); 
    $scope.now = $scope.now + 1000; 

}; 
+0

为什么你要麻烦?只要使用Datefilter https://docs.angularjs.org/api/ng/filter/date –

回答

0

我在一些研究后得到了我的答案。在下面找到它:

var starttime = starttime; 
    var endtime = endtime; 
    if (starttime.indexOf('Z') == -1 && endtime.indexOf('Z')) { 
     starttime = starttime.replace(' ', 'T') + 'Z'; 
     endtime = endtime.replace(' ', 'T') + 'Z'; 
    }