There is a function - a countdown timer. It counts from the specified number of seconds to zero.

function countDown() { var seconds = 70997; var timer = setInterval(function() { if (seconds > 0) { seconds --; if (seconds < 10) { seconds = "0" + seconds; } $(".timer .seconds").text(seconds); } else { clearInterval(timer); } }, 1000); } 

seconds = 70997 - 19 hours / 43 minutes / 17 seconds. How to divide the output in hours / seconds / minutes in the timer?

1 answer 1

There is a simple division

 function countDown() { var seconds = 70997; var timer = setInterval(function() { if (seconds > 0) { seconds --; var h = seconds/3600 ^ 0, m = (seconds-h*3600)/60 ^ 0, s = seconds-h*3600-m*60, time = (h<10?"0"+h:h)+" ч. "+(m<10?"0"+m:m)+" мин. "+(s<10?"0"+s:s)+" сек."; $("body").text(time); } else { clearInterval(timer); } }, 1000); } $(function() { countDown() }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>