-2

Suppose I have an integer number as a variable. (this number can be any integer number).

Now I want to create a countdown timer based on this number on the page.

To create countDown, I am using jquery-countdownTimer plugin.

A simple usage of this plugin is like this :

$(function(){
    $("#hms_timer").countdowntimer({
        hours : 3‚
        minutes : 10‚
        seconds : 10‚
        size : "lg"‚
        pauseButton : "pauseBtnhms"‚
        stopButton : "stopBtnhms"
    });
});

As you see , it gets hours , minutes and seconds in 3 separate numbers.

Now my question is how can I convert an integer number to Equivalent hours , minutes and seconds in simplest way?

Ahmad Badpey
  • 6,348
  • 16
  • 93
  • 159

1 Answers1

1

function getTime(s) {
  var secs = parseInt(s, 10); // don't forget the second param
  var hours = Math.floor(secs / 3600);
  var minutes = Math.floor((secs - (hours * 3600)) / 60);
  var seconds = secs - (hours * 3600) - (minutes * 60);

  return {
    hours: hours,
    minutes: minutes,
    seconds: seconds
  };
}

var time = getTime("3792");
alert("Hours: " + time.hours + "\nMinutes: " + time.minutes + "\nSeconds: " + time.seconds);
Pugazh
  • 9,453
  • 5
  • 33
  • 54