Skip to content

Instantly share code, notes, and snippets.

@dmartinezGN
Created June 15, 2021 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmartinezGN/115fa0894f7d306a7c86b566d41a9cce to your computer and use it in GitHub Desktop.
Save dmartinezGN/115fa0894f7d306a7c86b566d41a9cce to your computer and use it in GitHub Desktop.
Script
<script>
countdown('07/15/2021 8:00 PM', 'timer2'); //date format: mm/dd/yyyy hh:mm AM
function countdown(dt, id)
{
var end = new Date(dt);
var _second = 1000;
var _minute = _second * 60;
var _hour = _minute * 60;
var _day = _hour * 24;
var timer2;
function showRemaining() {
var now = new Date();
var distance = end - now;
if (distance < 0) {
clearInterval(timer);
document.getElementById(id).innerHTML = 'EL DÍA HA LLEGADO!'; //Displays when countdown is complete
return;
}
var days = Math.floor(distance / _day);
var hours = Math.floor((distance % _day) / _hour);
var minutes = Math.floor((distance % _hour) / _minute);
var seconds = Math.floor((distance % _minute) / _second);
document.getElementById(id).innerHTML = days + ' DIAS ';
document.getElementById(id).innerHTML += hours + ' HORAS ';
document.getElementById(id).innerHTML += minutes + ' MINUTOS ';
document.getElementById(id).innerHTML += seconds + ' SEGUNDOS';
}
timer = setInterval(showRemaining, 1000);
}
/**
* Do not remove this section; it allows our team to troubleshoot and track feature adoption.
* TS:0002-03-083
*/
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment