Spirit_on,
время указать в секундах ... для примера поставлено 30сек
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Демо</title>
<script type='text/javascript' src='http://code.jquery.com/jquery-2.1.0.min.js'></script>
<style type='text/css'>
</style>
<script>
$(window).load(function(){
function getTargetDate(Milliseconds_to_count){
var t = new Date();
t.setMilliseconds(t.getMilliseconds()+Milliseconds_to_count)
return t.getTime();
}
//Время меняем тут:
var Milliseconds_to_count = 30 * 1000; // отсчет в секундах - 7 часов = 7 * 60 * 60 * 1000
var time = 200
var target_date = getTargetDate(JSON.parse(localStorage.getItem("Milliseconds"))|| Milliseconds_to_count);
// update the tag with id "countdown" every 1 second
var timer = function () {
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
var d = document.getElementById("day");
var h = document.getElementById("hour");
var m = document.getElementById("minute");
var s = document.getElementById("second");
// find the amount of "seconds" between now and target
var current_date = new Date().getTime();
var seconds_left = (target_date - current_date);
localStorage.setItem("Milliseconds", JSON.stringify(seconds_left));
if(seconds_left < 1000){
target_date = getTargetDate(Milliseconds_to_count);
time = 1000;
}
seconds_left /= 1000;
// do some time calculations
days = parseInt(seconds_left / 86400);
seconds_left = seconds_left % 86400;
hours = parseInt(seconds_left / 3600);
seconds_left = seconds_left % 3600;
minutes = parseInt(seconds_left / 60);
seconds = parseInt(seconds_left % 60);
if(days < 10){
days = "0" + days;
}
if(hours < 10){
hours = "0" + hours;
}
if(minutes < 10){
minutes = "0" + minutes;
}
if(seconds < 10){
seconds = "0" + seconds;
}
d.innerHTML = days;
h.innerHTML = hours;
m.innerHTML = minutes;
s.innerHTML = seconds;
window.setTimeout(timer, time)
};
timer()
});
</script>
</head>
<body>
<div id="countdown">
<span id="day" >00</span>
<span id="hour" >00</span>
<span id="minute" >00</span>
<span id="second" >00</span>
</div>
</body>
</html>