I am trying to work on timer for my website b/w two date ( now date and my cdate input) please i would like someone to help me out with my code
function ctimer() {
var cdate = new Date("2017-03-31 13:06:57");
var now = new Date();
var timeDiff = cdate.getTime() - now.getTime();
if (timeDiff <= 0) {
clearTimeout(timer);
}
var seconds = Math.floor(timeDiff / 1000);
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
var days = Math.floor(hours / 24);
document.getElementById("daysBox").innerHTML = days;
document.getElementById("hoursBox").innerHTML = hours;
document.getElementById("minsBox").innerHTML = minutes;
document.getElementById("secsBox").innerHTML = seconds;
var timer = setTimeout('ctimer()',1000);
}
<span id="daysBox"></span>
Days
<span id="hoursBox"></span>
Hrs:
<span id="minsBox"></span>
Min:
<span id="secsBox"></span>
Sec
<script>ctimer();</script>
Add this after the day variable
var days = Math.floor(hours / 24);
hours %= 24;
minutes %= 60;
seconds %= 60;
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments