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;
};
爲什麼你要麻煩?只要使用Datefilter https://docs.angularjs.org/api/ng/filter/date –