Skip to content

Instantly share code, notes, and snippets.

@grovertb
Last active September 21, 2017 16:33
Show Gist options
  • Save grovertb/5c1905d3643a1e4c3ea003c028096357 to your computer and use it in GitHub Desktop.
Save grovertb/5c1905d3643a1e4c3ea003c028096357 to your computer and use it in GitHub Desktop.
function getTime() {
now = new Date();
fecha = new Date("2017-10-30 00:00:00");
diffDate = (fecha - now)
months = diffDate / 1000 / 60 / 60 / 24 / 30;
monthsRound = Math.floor(months);
days = diffDate / 1000 / 60 / 60 / 24 - (30 * monthsRound);
daysAux = diffDate / 1000 / 60 / 60 / 24;
daysAuxRound = Math.floor(daysAux);
daysRound = Math.floor(days);
hours = diffDate / 1000 / 60 / 60 - (24 * daysAuxRound);
hoursRound = Math.floor(hours);
minutes = diffDate / 1000 /60 - (24 * 60 * daysAuxRound) - (60 * hoursRound);
minutesRound = Math.floor(minutes);
seconds = diffDate / 1000 - (24 * 60 * 60 * daysAuxRound) - (60 * 60 * hoursRound) - (60 * minutesRound);
secondsRound = Math.round(seconds);
if (daysRound <= "-1") {
console.log('Fecha anterior a hoy')
}
else{
// document.getElementById('dias').innerHTML = daysRound;
// document.getElementById('horas').innerHTML = hoursRound;
// document.getElementById('min').innerHTML = minutesRound;
// document.getElementById('seg').innerHTML = secondsRound;
console.log(`mes: ${monthsRound} - día: ${daysRound} - hora: ${hoursRound} - minuto: ${minutesRound} - segundo: ${secondsRound} `)
}
}
window.setInterval(()=> getTime(), 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment