3
I have a contact day, hour, minute and second, from there I program for example: in 2 days (regressive), I would like when it zeroes start counting again, type 2 in 2 days, or 1 in 1, not to need every time Zera have to keep making date changes!
Follow the code:
var target_date = new Date("\n" + " October 15, 2019").getTime();
var dias, horas, minutos, segundos;
var regressiva = document.getElementById("regressiva");
setInterval(function() {
var current_date = new Date().getTime();
var segundos_f = (target_date - current_date) / 1000;
dias = parseInt(segundos_f / 86400);
segundos_f = segundos_f % 86400;
horas = parseInt(segundos_f / 3600);
segundos_f = segundos_f % 3600;
minutos = parseInt(segundos_f / 60);
segundos = parseInt(segundos_f % 60);
document.getElementById('dia').innerHTML = dias;
document.getElementById('hora').innerHTML = horas;
document.getElementById('minuto').innerHTML = minutos;
document.getElementById('segundo').innerHTML = segundos;
}, 1000);
then when Zera it starts -1 -1 -1 -1 type like this, starts negatively and goes!
– Paulo Junior
when I update the page it comes back from the beginning
– Paulo Junior
@Paulojunior every time the page is (re)loaded the script is interpreted again. To save keeping information between page exchanges use some mechanism such as localStorage, sessionStorage, cookies, Session, etc..
– Marcelo Vismari