I found a script that will help you. Well, one should still check the possibilities, the most correct would be to work with database, where you would take the date/time end and subtract from the date/time end, where these dates should come from the database server, because the date/time of the client computer may be wrong.
Anyway follows a good example, but it meets if the promotion is within 24 hours. I will try to improve the code I found in this question here, and count the days too.
if (document.getElementById('countdownTimer')) {
pad = function(n, len) { // leading 0's
var s = n.toString();
return (new Array( (len - s.length + 1) ).join('0')) + s;
};
var timerRunning = setInterval(
function countDown() {
var target = 22; // **defina aqui a hora final**
var now = new Date();
//Put this in a variable for convenience
var weekday = now.getDay();
if(weekday == 0){// Domingo? adiciona 24 horas
target += 24;
}//keep this before the sunday, trust me :>
if(weekday == 6){//Sábado? adiciona 48 horas
target += 48;
}
//If between Monday and Friday,
//check if we're past the target hours,
//and if we are, abort.
if((weekday>=1) && (weekday<=5)){
if (now.getHours() > target) { //stop the clock
return 0;
}
}
var hrs = (target - 1) - now.getHours();
if (hrs < 0) hrs = 0;
var mins = 59 - now.getMinutes();
if (mins < 0) mins = 0;
var secs = 59 - now.getSeconds();
if (secs < 0) secs = 0;
var str = pad(hrs, 2) + ':' + pad(mins, 2) + '.<small>' + pad(secs, 2) + '</small>';
document.getElementById('countdownTimer').innerHTML = str;
}, 1000
);
}
Client logs into server?
– Sergio
No, it’s a promotional display flag on a website, look at the first helmet on this site: http://www.rs1.com.br/shark
– Julio Santos
You have to receive this time from the server and the counter reads of this value, there is no other way, I believe.
– DontVoteMeDown
I understand, how could I do it ? Could I take the time from the machine ?
– Julio Santos
Julio the problem is that if you are associated with a certain user only if he logs in. You can do it in the browser with localStorage but if the user uses another computer the program will not distinguish...
– Sergio