Skip to content

Instantly share code, notes, and snippets.

@cosmez
Created October 28, 2016 03:37
Show Gist options
  • Save cosmez/a2eaf43991d4fe20678b02db70749e23 to your computer and use it in GitHub Desktop.
Save cosmez/a2eaf43991d4fe20678b02db70749e23 to your computer and use it in GitHub Desktop.
Como generar un timer con cuenta regresiva
<html>
<head>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.15.2/moment.min.js"></script>
<title>pruebs</title>
</head>
<body>
<div id="resultado">
</div>
<div id="minuto">
</div>
<div id="segundo">
</div>
</body>
<script type="text/javascript">
var final = moment("2017-06-15");
setInterval(function() {
var inicio = moment();
var duracion = final.diff(inicio);
var intervalo = moment(duracion);
var mes = intervalo.month()+1;
var diaDelMes = intervalo.date();
var hora = intervalo.hour();
var minuto = intervalo.minute();
var segundo = intervalo.second();
var resultado = (intervalo.format("MM/DD HH:mm:ss"));
$("#resultado").html(mes + " Meses " + diaDelMes + " Dias " + hora + " Horas " + minuto + " Minutos " + segundo + " Segundos");
$("#minuto").html(minuto);
$("#segundo").html(segundo);
}, 1000);
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment