1

Javascript function

<script type="text/javascript">                          
      var MAX_COUNTER = 100;
    var counter = null;
    var counter_interval = null;

    function updateCounter() {
        var msg = '';
        if (counter > 0) {
            counter -= 1;
            msg = counter;
            setCookie('counter', counter, 1);
        }
        else {
            msg = "Counting finished.";
            stopCounter();
        }
        var el = document.getElementById('counter');
        if (el) {
            el.innerHTML = msg;
        }
    }
    function resetCounter() {
        counter = MAX_COUNTER;
    }
    function stopCounter() {
        window.clearInterval(counter_interval);
        deleteCookie('counter');
    }
    function startCounter() {
        stopCounter();
        counter_interval = window.setInterval(updateCounter, 1000);
    }
    </script>

I have this function to make a countdown timer..it output the number depends on what i put on the MAX_COUNTER..but i want to convert it to hh:mm:ss ...since im a newbie in javascript. how to convert it to hh:mm:ss format? plss help..:(

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Zurreal
  • 191
  • 1
  • 3
  • 15

1 Answers1

2

Put this code into your update function

var min=parseInt(MAX_COUNTER/60);
var sec=MAX_COUNTER%60;
var hours=parseInt(min/60);
Taron Mehrabyan
  • 2,199
  • 2
  • 20
  • 27