I want to make the time auto reset according to the time zone of the area.
The problem is that when the code resets after 24 hours or one day - when it reaches 0 seconds the value returns to 24 hours but the time remains on '24 Hours'?
Although tried with 60 seconds, when the value reaches zero, it returns from 60 seconds again and a countdown is like an endless loop (this is what want but need to do it on daily basis)
Here is my code:
let na;
setInterval(function(){
na = moment().tz("America/New_York").format("hh:mm A"); //i used this pkg 'moment' to take the time in a region and i want it to check with setInterval to update the time every seconds because that's the only way i know to take the time of a country
//day = check.format('dddd'); i just removed this part cuz i need it later
})
let timer1; // i put this because want to share value in embed
try {
//na
let NAtime = setInterval(checkNA);
async function checkNA() {
//if(na === timeResetNA) { i removed this part just to check if return to zero it returns to its own value and then completes the counting
timer1 = circleTimeDailyNA;
console.log('na done')
// countdown start a day!
nacountDown = setInterval(function () {
timer1 -= 1;
console.log('na1: ' + timer1);
if (timer1 <= 0){
clearInterval(nacountDown);
timerend1 = setInterval(function(){
console.log('daily gone!')
timer1 = circleTimeDailyNA; // reset to 1day
clearInterval(timerend1)
reCheckTimerNA();
})
}
},1000)
clearInterval(NAtime)
//}
}
function reCheckTimerNA() {
console.log('the function passed to recheck.')
NAtime = setInterval(checkNA); // will make countdown again
};
} catch(err) {
console.log(err)
}