我正在尝试使用Angular js从我的数据库中以hr:min:sec的格式显示时间但是在Mozilla和Safari中获得错误NaN hr NaN min NaN,而它在Chrome中工作正常。这是我的代码:
$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 :(得分: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';
}