Snippets Collections
<!-- Html -->
<div id="timer">
  <div id="days"></div>
  <div id="hours"></div>
  <div id="minutes"></div>
  <div id="seconds"></div>
</div>

<!-- Js Code -->
function makeTimer() {
  //	var endTime = new Date("29 April 2018 9:56:00 GMT+01:00");	
  var endTime = new Date("30 July 2022 12:00:00 GMT+01:00");			
  endTime = (Date.parse(endTime) / 1000);
  var now = new Date();
  now = (Date.parse(now) / 1000);
  var timeLeft = endTime - now;
  var days = Math.floor(timeLeft / 86400); 
  var hours = Math.floor((timeLeft - (days * 86400)) / 3600);
  var minutes = Math.floor((timeLeft - (days * 86400) - (hours * 3600 )) / 60);
  var seconds = Math.floor((timeLeft - (days * 86400) - (hours * 3600) - (minutes * 60)));
  if (hours < "10") { hours = "0" + hours; }
  if (minutes < "10") { minutes = "0" + minutes; }
  if (seconds < "10") { seconds = "0" + seconds; }
  $("#days").html(days + "<span>Days</span>");
  $("#hours").html(hours + "<span>Hours</span>");
  $("#minutes").html(minutes + "<span>Minutes</span>");
  $("#seconds").html(seconds + "<span>Seconds</span>");		
}
setInterval(function() { makeTimer(); }, 1000);
star

Wed Jul 20 2022 10:06:18 GMT+0000 (Coordinated Universal Time)

#code #html #javascript #countdowntimer

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension