<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>
<link rel="stylesheet" type="text/css" href="/css/result-light.css">
<style type='text/css'>
#timer_container{
}
</style>
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
// когда начинаем
// формат Dane( гггг, м(0 - январь), д, ч, мин, сек )
var start_date = new Date( 2013, 9, 17, 0, 0, 0 ).getTime();
// до какого времени считаем
var target_date = new Date( 2013, 9, 31, 0, 0, 0 ).getTime();
var timer_container = $( '#timer_container' );
var counter = setInterval(function () {
var days_remaining, hours_remaining, minutes_remaining;
// текущее время
var current_date = new Date().getTime();
// сколько секунд осталось
var seconds_left = parseInt( (target_date - current_date) / 1000 );
if( 0 >= seconds_left || start_date > current_date ){ // приехали
clearInterval( counter );
return;
}
days_remaining = parseInt( seconds_left / ( 60 * 60 * 24 ) );
seconds_left = seconds_left % ( 60 * 60 * 24 );
hours_remaining = parseInt( seconds_left / ( 60 * 60 ) );
seconds_left = seconds_left % ( 60 * 60 );
minutes_remaining = parseInt( seconds_left / 60 );
seconds_left = seconds_left % 60;
timer_container.html( 'days: ' + days_remaining + ', hours: ' + hours_remaining + ', minutes: ' + minutes_remaining + ', seconds: ' + seconds_left );
}, 1000 );
});//]]>
</script>
</head>
<body>
<div id="timer_container"></div>
</body>
</html>