2017-02-16 53 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'; 
    }