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 :: SHOPIFY LANGUAGE SELECTOR 
Javascript :: jquery add class except this 
Javascript :: how to convert utc time to local time angular 
Javascript :: react native flatlist container style 
Javascript :: return nothing javascript 
Javascript :: js string to boolean 
Javascript :: js for of 
Javascript :: toLocalString 
Javascript :: create javascript array with 1 value 
Javascript :: vuelidate required if another props 
Javascript :: lodash find all in array 
Javascript :: google geocode nodejs 
Javascript :: how to select a class and then change the children of that class with javascript 
Javascript :: npm ERR! Error: connect ECONNREFUSED 
Javascript :: how to add element in json object 
Javascript :: how to insert div around element in javascript 
Javascript :: spread operator javascript 
Javascript :: js comments 
Javascript :: force delete and restore in sequelize 
Javascript :: react leaflet disable zoom 
Javascript :: convert html to docx javascript 
Javascript :: jquery create array 
Javascript :: Make Floating label TextInput in react native 
Javascript :: update a certain key in dictionary javascript 
Javascript :: javascript datatypes 
Javascript :: how to get location javascript 
Javascript :: javascript json trypass 
Javascript :: js key down 
Javascript :: js two value from array after reduce 
Javascript :: javascript call php function with parameters 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =