Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript countdown timer

<!-- Display the countdown timer in an element -->
<p id="demo"></p>

<script>
// Set the date we're counting down to
var countDownDate = new Date("Mar 16, 2021 15:37:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);

  // Display the result in the element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished, write some text
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
</script>
Comment

countdown javascript

const startNumber = 10, stopNumber = 0, skip = 1;
for (let i = startNumber; i >= stopNumber; i -= skip) {
	console.log(i);
}
/*
10
9
8
7
6
5
4
3
2
1
0
*/
Comment

js countdown

/** https://www.youtube.com/watch?v=x7WJEmxNlEs */
//timeInMins repersent time in minutes. eg: timeInMins = 5 --> 5 minutes
function timer(timeInMins) {
    const demo = document.getElementById("demo");
 
    console.log("timeInMins: " + timeInMins);

    let time = 60 * prepareTime;

   setInterval(function () {
        let minutes = Math.floor(time / 60);
        let seconds = time % 60;

        minutes = minutes < 10 ? '0' + minutes : minutes;
        seconds = seconds < 10 ? '0' + seconds : seconds;
        demo.innerHTML = `${minutes}:${seconds}`;
        time--;
    }, 1000);


}
Comment

JavaScript countdown

<!DOCTYPE HTML>
<html>
<body>

<p id="demo"></p>
<button onclick="countdownTimeStart()">Start Timer</button>

<script>
// Set the date we're counting down to

function countdownTimeStart(){

var countDownDate = new Date("Sep 25, 2025 15:00:00").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

    // Get todays date and time
    var now = new Date().getTime();
    
    // Find the distance between now an the count down date
    var distance = countDownDate - now;
    
    // Time calculations for days, hours, minutes and seconds
    var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((distance % (1000 * 60)) / 1000);
    
    // Output the result in an element with id="demo"
    document.getElementById("demo").innerHTML = hours + "h "
    + minutes + "m " + seconds + "s ";
    
    // If the count down is over, write some text 
    if (distance < 0) {
        clearInterval(x);
        document.getElementById("demo").innerHTML = "EXPIRED";
    }
}, 1000);
}
</script>

</body>
</html>
 Run code snippet
Comment

countdown javascript

// To make a countdown you can use a for loop and console.log(msg);

console.log("We have liftoff in T minus...");
for (let i = 10; i >= 0; i--) {
	console.log(i);
}
console.log("We have liftoff!");
Comment

countdown js

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8" />
    <title>Countdown timer using HTML and JavaScript</title>
</head>

<body>
    <p id="demo"></p>

    <script>
        // Set the date we're counting down to
        var countDownDate = new Date("Jan 5, 2023 15:37:25").getTime();

        // Update the count down every 1 second
        var x = setInterval(function () {

            // Get today's date and time
            var now = new Date().getTime();

            // Find the distance between now and the count down date
            var distance = countDownDate - now;

            // Time calculations for days, hours, minutes and seconds
            var days = Math.floor(distance / (1000 * 60 * 60 * 24));
            var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
            var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
            var seconds = Math.floor((distance % (1000 * 60)) / 1000);

            // Display the result in the element with id="demo"
            document.getElementById("demo").innerHTML = days + "d " + hours + "h "
                + minutes + "m " + seconds + "s ";

            // If the count down is finished, write some text
            if (distance < 0) {
                clearInterval(x);
                document.getElementById("demo").innerHTML = "EXPIRED";
            }
        }, 1000);
    </script>
</body>

</html>
Comment

PREVIOUS NEXT
Code Example
Javascript :: import card content material ui 
Javascript :: js merge 2 form data 
Javascript :: jquery ajax form submit example 
Javascript :: dynamic navigation with subitems 
Javascript :: icon shwoing a box react native vector icons 
Javascript :: javascript for loop array 
Javascript :: filter object js 
Javascript :: rock paper scissors javascript 
Javascript :: javascript typewriter effect 
Javascript :: how to print console in javascript 
Javascript :: data-dismiss="modal" in js 
Javascript :: nodejs update in mysql 
Javascript :: remove all elements of one array from another javascript 
Javascript :: Scroll elementleft using js 
Javascript :: inverse of stringify js 
Javascript :: delete element html javascript 
Javascript :: vue loop 
Javascript :: how to add element in arry in js 
Javascript :: same click event in multiple elements in on event 
Javascript :: jquery get tr value 
Javascript :: how to find smallest number in array js 
Javascript :: jshint 6 atom 
Javascript :: loop over an array 
Javascript :: mutable array methods in javascript 
Javascript :: how to write a comment in react js 
Javascript :: javascript for loop array backwards 
Javascript :: for javascript 
Javascript :: react memo 
Javascript :: get element by name in jquery 
Javascript :: new Date().now 
ADD CONTENT
Topic
Content
Source link
Name
7+9 =