0

I had a code below show count up timer. How can I get calculate to get day?

function a() {

  var time;

  time = 0;

  setInterval((function () {

    var hour, min, sec, str;

    time++;

    var sec = time % 60;

    var min = (time - sec) / 60 % 60;

    var hour = (time - sec - (min * 60)) / 3600;

    var count = hour + ':' + ('0' + min).slice(-2) + ':' + ('0' + sec).slice(-2);

    $('.response-time').html(count);

  }), 1000);

};

a();
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="response-time"></div>
Sheraff
  • 5,730
  • 3
  • 28
  • 53
Sang Tran
  • 47
  • 1
  • 7
  • 1
    you can use `var day = time / (24*60*60);` – Iłya Bursov Feb 21 '20 at 21:53
  • 2
    note - setInterval does not guarantee that function will be called exactly every second, there could be fluctuations, so such method will go out of sync soon, it is better to store start time, in function get current time and calculate difference – Iłya Bursov Feb 21 '20 at 21:54
  • as to @IłyaBursov's point, here's one of my answers on the topic: https://stackoverflow.com/questions/59591214/how-am-i-able-to-add-timing-to-javascript-that-alters-text-every-second/59591423#59591423 – Sheraff Feb 21 '20 at 21:55

0 Answers0