const countDownTime = new Date().getTime() + 24 * 60 * 6;
let val = setInterval(function() {
const now = new Date().getTime();
const timeLeft = countDownTime - now;
const days = Math.floor(timeLeft / (1000 * 60 * 60 *24));
const hours = Math.floor( (timeLeft / (1000 * 60 * 60)) % 24);
const minutes = Math.floor((timeLeft / 1000 / 60) % 60);
const seconds = Math.floor((timeLeft / 1000) % 60);
console.log(days + "d " + hours + "h " + minutes + "m " + seconds + "s");
if (timeLeft < 0) {
clearInterval(val);
}
}, 1000);
/*
run:
"0d 0h 0m 7s"
"0d 0h 0m 6s"
"0d 0h 0m 5s"
"0d 0h 0m 4s"
"0d 0h 0m 3s"
"0d 0h 0m 2s"
"0d 0h 0m 1s"
"0d 0h 0m 0s"
"-1d -1h -1m -1s"
*/