Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

jquery countdown timer

// Set the date we're counting down to
var countDownDate = new Date("Jan 5, 2024 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);
    
  // Output the result in an element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + 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);
//example: https://www.w3schools.com/howto/tryit.asp?filename=tryhow_js_countdown
Comment

jquery timer countdown

var timer2 = "5:01";
var interval = setInterval(function() {


  var timer = timer2.split(':');
  //by parsing integer, I avoid all extra string processing
  var minutes = parseInt(timer[0], 10);
  var seconds = parseInt(timer[1], 10);
  --seconds;
  minutes = (seconds < 0) ? --minutes : minutes;
  if (minutes < 0) clearInterval(interval);
  seconds = (seconds < 0) ? 59 : seconds;
  seconds = (seconds < 10) ? '0' + seconds : seconds;
  //minutes = (minutes < 10) ?  minutes : minutes;
  $('.countdown').html(minutes + ':' + seconds);
  timer2 = minutes + ':' + seconds;
}, 1000);
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery replace text in div 
Javascript :: js foreach method 
Javascript :: antd react native 
Javascript :: js if string not empty 
Javascript :: how to remove an object from an array javascript 
Javascript :: copy paste menu react native textinput disable 
Javascript :: function inside object javascript 
Javascript :: open in a new tab react 
Javascript :: Addition aruments in javascript 
Javascript :: Javascript Show HTML Elements 
Javascript :: how to chunk a base 64 in javascript 
Javascript :: How to set the background image URL of an element using jQuery 
Javascript :: remove last element from array javascript 
Javascript :: react dynamic load script 
Javascript :: javascript delay action 
Javascript :: footer react 
Javascript :: react conditional class 
Javascript :: debug.xcconfig: unable to open file react native 
Javascript :: i want to redirect to main page from iframe javascript 
Javascript :: two decimal places javascript 
Javascript :: react native build android 
Javascript :: ionic capacitor splash screen spinner 
Javascript :: print object keys 
Javascript :: angular configure routes 
Javascript :: jquery select dropdown 
Javascript :: auto import vscode not working 
Javascript :: atob javascript 
Javascript :: javascript image to blob 
Javascript :: how avoid populate mongoose return password 
Javascript :: javascript change title 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =