//倒计时函数 $scope.showtime=function(endTime){ var time_start = new Date().getTime(); //设定当前时间 var time_end = new Date(endTime).getTime(); //设定目标时间 // 计算时间差 var time_distance = time_end - time_start; if (time_distance > 0) { // 天 var int_day = Math.floor(time_distance / 86400000) time_distance -= int_day * 86400000; // 时 var int_hour = Math.floor(time_distance / 3600000) time_distance -= int_hour * 3600000; // 分 var int_minute = Math.floor(time_distance / 60000) time_distance -= int_minute * 60000; // 秒 var int_second = Math.floor(time_distance / 1000) $scope.countDown={ dayten:parseInt(int_day / 10), dayone:parseInt(int_day % 10), hourten:parseInt(int_hour / 10), hourone:parseInt(int_hour % 10), minuteten:parseInt(int_minute / 10), minuteone:parseInt(int_minute % 10), secondten:parseInt(int_second / 10), secondone:parseInt(int_second % 10) }; $timeout(function(){ $scope.showtime(endTime) }, 1000); } }
如下24小时倒计时