JSFiddle - React, Tailwind, and code Playground
by antouank
JavaScript
function startCountdown(){
var d = new Date();
d.setHours(0,0,0,0);
d = d.getTime() + 24*60*60*1000;
function showDiffMs(){
var diff = d-Date.now();
if(diff){
// you have the diff in ms here
console.log(parseInt(diff/1000)+' seconds remaining till midnight');
}
}
return setInterval(function(){
showDiffMs();
},1000);
};
var timer = startCountdown();
// clearInterval(timer); // stop countdown