Create Counter by incrementing a separate Digit every 60 seconds

Asked

Viewed 52 times

-1

As I don’t have much knowledge of javascript I would like a little help on how to do this script down.

This script would be a counter where every 60 seconds points add up and that counter starts from date and time x date and time end

inserir a descrição da imagem aqui

1 answer

1

Check if this is what you want:

var cont = 0;
var pontos = 0;

function contador() {
  document.getElementById('tempo').innerHTML = cont;
  if(cont == 60){
    cont = 0;
    pontos++;
    document.getElementById('pontos').innerHTML = pontos;
  }
  cont++;
  setTimeout("contador()", 1000);
}

window.onload = function () {
  //Insere as datas de inicio e fim do contador.
  var datainicio = '03/04/2019 00:00:00';
  var datafim = '05/04/2019 00:00:00';

  var hoje = new Date();
  var dd = String(hoje.getDate()).padStart(2, '0');
  var mm = String(hoje.getMonth() + 1).padStart(2, '0');
  var yyyy = hoje.getFullYear();
  var hh = String(hoje.getHours()).padStart(2, '0');
  var MM = String(hoje.getMinutes()).padStart(2, '0');
  var ss = String(hoje.getSeconds()).padStart(2, '0');

  hoje = mm + '/' + dd + '/' + yyyy + ' ' + hh + ':' + MM + ':' + ss;

  if(hoje >= datainicio && hoje <= datafim){
    contador();
  }
}
<b>Tempo: </b><span id="tempo">0</span></br>
<b>Pontos: </b><span id="pontos">0</span>

  • show... this same just could not reset if an update takes place

  • You will have to work with database for this type of recording if I helped you mark as response. Thank you!

  • I thought of taking the current seconds date_default_timezone_set('America/Sao_paulo'); $hour = date('H:i:s'); taking the current time with current second

  • like the count starts from the current schedule and second would not be able to do so ?

  • I don’t quite understand your doubt, try to be a little clearer on what you need.

  • Then example the count would start at 01/04/2019 at 12:00:00 until 05/04/2019 12:00:00. We know that this interval has 5760 minutes that would be the "Points" . would be to make the calculation of minutes between dates and time always showing a chronometer updating the points that would actually be minutes

  • https://www.topster.pt/calendario/zeitrechner.php?styp=zeit&sdatum=2019-04-01&szeit=12%3A00%3A00&typ=zeit&edatum=2019-04-05&ezeit=12%3A00%3A00&subDazu=%2B&jahredazu=0&wochendazu=0&tagedazu=3&zeitdazu=00%3A00%3A00

  • In case you want a minute count remaining between two dates?

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.