I have to count down the system clock according to two different times. in hours, minutes, seconds. For example, a day is 24 hours.
Between 15:00:00 and 13:00:00 = 22 hours. When the clock is 15:00:00, it should count back from 22:00:00. and it must be 00:00:00 at 13:00:00.
Between 13:00:00 and 15:00:00 = 2 hours. When the clock is 13:00:00, it should count back from 2:00:00. and it must be 00:00:00 at 15:00:00.
i want it to repeat daily.
I've tried so hard for a few days, but I couldn't. please help me.
I add it again with the code I used.
HTML / XML
"text/javascript" src="jquery-3.4.1.js">
"text/javascript">
var timer = setInterval(function() {
var now= new Date().getTime();
var endtime= new Date(13);
var t = now - endtime;
var endtime2= new Date(15);
var y = now - endtime2;
if (t
let hours = Math.floor((t % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((t % (1000 * 60)) / 1000);
document.getElementById("timer-hours").innerHTML= ("0" + hours).slice(-2) +
" hr";
document.getElementById("timer-minutes").innerHTML= ("0" + minutes).slice(-2) +
" mn";
document.getElementById("timer-seconds").innerHTML= ("0" + seconds).slice(-2) +
" sc";
}
if (y >=22) {
let hours = Math.floor((y % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
let minutes = Math.floor((y % (1000 * 60 * 60)) / (1000 * 60));
let seconds = Math.floor((y % (1000 * 60)) / 1000);
document.getElementById("timer-hours").innerHTML= ("0" + hours).slice(-2) +
" hr";
document.getElementById("timer-minutes").innerHTML= ("0" + minutes).slice(-2) +
" mn";
document.getElementById("timer-seconds").innerHTML= ("0" + seconds).slice(-2) +
" sc";
}
else {
document.getElementById("timer").innerHTML = "There is a problem!";
}
}, 1000);
class="container">
"timer">
"timer-hours">
"timer-minutes">
"timer-seconds">
Asma KhalidRank #160 · 14.7K reputationPosted Jan 19, 2021, 9:00 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Jan 19, 2021, 9:18 AM EST
Sachin SinghRank #66 · 26.2K reputationPosted Jan 19, 2021, 1:22 PM EST
max novaa7 reputationPosted Jan 20, 2021, 2:32 PM EST