Mozilla Firefox 版本低于 45 时出现 NaN hr NaN min NaN sec 错误
NaN hr NaN min NaN sec error in Mozilla Firefox version less than 45
我正在尝试使用 Angular js 从我的数据库中以 hr:min:sec 格式显示时间,但在 Mozilla 和 Safari 中出现错误 NaN hr NaN min NaN 而在 [=15= 中工作正常].这是我的代码:
$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;
};
经过一番研究,我得到了答案。在下面找到它:
var starttime = starttime;
var endtime = endtime;
if (starttime.indexOf('Z') == -1 && endtime.indexOf('Z')) {
starttime = starttime.replace(' ', 'T') + 'Z';
endtime = endtime.replace(' ', 'T') + 'Z';
}
我正在尝试使用 Angular js 从我的数据库中以 hr:min:sec 格式显示时间,但在 Mozilla 和 Safari 中出现错误 NaN hr NaN min NaN 而在 [=15= 中工作正常].这是我的代码:
$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;
};
经过一番研究,我得到了答案。在下面找到它:
var starttime = starttime;
var endtime = endtime;
if (starttime.indexOf('Z') == -1 && endtime.indexOf('Z')) {
starttime = starttime.replace(' ', 'T') + 'Z';
endtime = endtime.replace(' ', 'T') + 'Z';
}