Question

On my app, I have a command:

@uptime = 'uprecords -s | awk '{ print $5 }'

that returns the current uptime from computer (using uptimed).
it returns something like 01:00:00 (hours, minutes, seconds) and I want to count up this time.
How do I do that? I tried some count up jquery plugins but none of them worked like I want How do you guys count up?
Thanks in advance

edit
I think I wasn't clear enough
What I want is to catch this uptime from my server (already done it), and via javascript, make it dinamically, counting up this current uptime, so if the user got away from keyboard, by example, the uptime still increases

Was it helpful?

Solution

You can use setInterval:

var seconds = 2642; // uptime in seconds
var timer = setInterval(
    function() {
        seconds++;
    }, 1000
);

Also, see this reference on JS time functions.

OTHER TIPS

I've done something (ugly) like this:

  function atualizarTimer() {
    //span.uptimed is a string like 01:23:45
    var time = $('span.uptimed').text();
    var d = new Date();
    times = time.split(':');
    d.setHours(times[0]);
    d.setMinutes(times[1]);
    d.setSeconds(times[2]);
    d.setSeconds(d.getSeconds()+1);

    document.getElementById("uptimed").innerHTML = d.getHours()+":"+d.getMinutes()+":"+d.getSeconds();
  }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top