Login Register
Code2night
  • Home
  • Guest Posts
  • Blog Archive
  • Tutorial
  • Languages
    • Angular
    • C
    • c#
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
  1. Home
  2. Blogpost

Countown Timer in Javascript

Date- Sep 17,2022

4969

countdown timer Timer in js


So , for creating a countdown timer  we have to add one div or span for showing the timer. So you can add this in the html


<div class="jumbotron">
    <h1>Jquery Countdown Timer</h1>
    
</div>


<div id="timer" style="font-size:30px">
    5:00
</div>

Now we have to add the javascript code for countdown timer. So you can add the following script in your page 

setTimeout(startTimer, 1000);

    var ResetTimer = function () {
         document.getElementById('timer').innerHTML =  "5 : 00";
    }

    function startTimer() {

        var presentTime = document.getElementById('timer').innerHTML;
        var timeArray = presentTime.split(/[:]+/);
        var m = timeArray[0];
        var s = checkSecond((timeArray[1] - 1));
        if (s == 59) { m = m - 1 }
        if (m < 0) {
            return
        }

        document.getElementById('timer').innerHTML =
            m + ":" + s;

        if (parseInt(m) == 0 && parseInt(s) == 0) {
            ResetTimer();

        }
        console.log(m)
        setTimeout(startTimer, 1000);

    }

    function checkSecond(sec) {
        if (sec < 10 && sec >= 0) { sec = "0" + sec }; // add zero in front of numbers < 10
        if (sec < 0) { sec = "59" };
        return sec;
    }

Here , you can see that we have added the timer for 5:00 minutes by default and then the countdown will work from that.When the timer will reach to zero we have down ResetTimer which we again set the value to initial value and timer will keep going.

You can check the output in the image

So this is how we can implement countdown timer in javascript.

S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

Chapter1 CSS
Dec 09, 2023
Anchor and Image tags in HTML
Dec 09, 2023
How to shuffle an array using javascript
May 07, 2022
Realtime Speech to Text converter using javascript
Dec 16, 2023

Comments

Contents

More in JavaScript

  • Slick Slider 14812 views
  • Card Number Formatting using jquery 11543 views
  • Alphanumeric validation in JavaScript 8759 views
  • Jquery Autocomplete 8369 views
  • Input Mask in Jquery 7438 views
View all JavaScript posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • C
  • c#
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page