let timer = setInterval(function() { // The dispatch date is just the variable name. You can change it wo whatever. As long as you change it where ever else it is been used as well. // the format for dispatch_date is ('2018-10-17 17:00:00') which is been pull from an input field with the id of "countdown_timer" const dispatch_date = new Date(document.getElementById("countdown_timer").value); const today = new Date(); // console.log("dispatch_date : "+dispatch_date); // console.log("today : "+today); // get the difference const diff = dispatch_date - today; // math let days = Math.floor(diff / (1000 * 60 * 60 * 24)); let hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); let minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60)); let seconds = Math.floor((diff % (1000 * 60)) / 1000); // display document.getElementById("timer").innerHTML = //Days - Hours - Minutes - Seconds "</div class='timer-p'>This Stock list Expires in </div> \ <div class=\"days\"> \ <div class=\"numbers\">" + days + "</div>Days</div> \ <div class=\"hours\"> \ <div class=\"numbers\">" + hours + "</div>Hours</div> \ <div class=\"minutes\"> \ <div class=\"numbers\">" + minutes + "</div>Minutes</div> \ <div class=\"seconds\"> \ <div class=\"numbers\">" + seconds + "</div>Seconds</div> \ </div>"; }, 1000);
Add to favorites