javascript countdown timer minutes seconds

Today, We want to share with you javascript countdown timer minutes seconds.In this post we will show you javascript countdown timer with user input, hear for javascript countdown timer hours, minutes seconds we will give you demo and example for implement.In this post, we will learn about How To Set Timer For 1 Hour? with an example.

How to create a countdown timer using JavaScript?

Example 1: countdown in js

function startTimer(duration, view_date) {
    var countdown = duration, minutes, seconds;
    setInterval(function () {
        minutes = parseInt(countdown / 60, 10);
        seconds = parseInt(countdown % 60, 10);

        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        view_date.textContent = minutes + ":" + seconds;

        if (--countdown < 0) {
            countdown = duration;
        }
    }, 1000);
}

window.onload = function () {
    var minutesOfFive = 60 * 5,
        view_date = document.querySelector('#time');
    startTimer(minutesOfFive, view_date);
};

Free Live Chat for Any Issue

Example 2: countdown in js

<body>
    <div>Registration closes in <span id="time">05:00</span> minutes!</div>
</body>

I hope you get an idea about javascript countdown timer code.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Rate this post