I want to run the countdown every 30 minutes in following code, countdown should be run in every 30 minutes.
function createCountDown(elementId, sec) {
var tms = sec;
var x = setInterval(function() {
var distance = tms*1000;
var days = Math.floor(distance / (1000 * 60 * 60 * 24));
var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((distance % (1000 * 60)) / 1000);
document.getElementById(elementId).innerHTML =days+"d: "+ hours + "h "+ minutes + "m " + seconds + "s ";
if (distance < 0) {
clearInterval(x);
document.getElementById(elementId).innerHTML = "{{__('COMPLETE')}}";
}
tms--;
}, 1000);
}
createCountDown('counter', {{\Carbon\Carbon::tomorrow()->diffInSeconds()}});
}
}
};
You can use setInterval().
setInterval(function () {
// Run your countdown script
....
}, 1800000)
// 1800000 // miliseconds = 30 minutes