max nova

max nova

  • NA
  • 2
  • 608

please help me for javascript code - ( countdown )

Jan 18 2021 10:00 PM

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.
 
 
  1. <!DOCTYPE html>  
  2. <html>  
  3. <head>  
  4.     <title></title>  
  5.     <script type="text/javascript" src="jquery-3.4.1.js"></script>  
  6. </head>  
  7. <body>  
  8.   
  9.   
  10. <script type="text/javascript">  
  11.   
  12.     var timer = setInterval(function() {  
  13.     var now= new Date().getTime();  
  14.       
  15.     var endtime= new Date(13);  
  16.     var t = now - endtime;  
  17.   
  18.     var endtime2= new Date(15);  
  19.     var y = now - endtime2;  
  20.           
  21.           
  22.         if (t <= 21) {  
  23.             let hours = Math.floor((t % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));  
  24.             let minutes = Math.floor((t % (1000 * 60 * 60)) / (1000 * 60));  
  25.             let seconds = Math.floor((t % (1000 * 60)) / 1000);  
  26.   
  27.             document.getElementById("timer-hours").innerHTML= ("0" + hours).slice(-2) +  
  28.                     "<span class='label'> hr</span>";  
  29.   
  30.             document.getElementById("timer-minutes").innerHTML= ("0" + minutes).slice(-2) +  
  31.                     "<span class='label'> mn</span>";  
  32.   
  33.             document.getElementById("timer-seconds").innerHTML= ("0" + seconds).slice(-2) +  
  34.                     "<span class='label'> sc</span>";  
  35.         }  
  36.         if (y >=22) {  
  37.             let hours = Math.floor((y % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));  
  38.             let minutes = Math.floor((y % (1000 * 60 * 60)) / (1000 * 60));  
  39.             let seconds = Math.floor((y % (1000 * 60)) / 1000);  
  40.   
  41.             document.getElementById("timer-hours").innerHTML= ("0" + hours).slice(-2) +  
  42.                     "<span class='label'> hr</span>";  
  43.   
  44.             document.getElementById("timer-minutes").innerHTML= ("0" + minutes).slice(-2) +  
  45.                     "<span class='label'> mn</span>";  
  46.   
  47.             document.getElementById("timer-seconds").innerHTML= ("0" + seconds).slice(-2) +  
  48.                     "<span class='label'> sc</span>";  
  49.         }  
  50.         else {  
  51.             document.getElementById("timer").innerHTML = "There is a problem!";  
  52.         }  
  53.     }, 1000);  
  54. </script>  
  55.   
  56. <div class="container">  
  57.     <p id="timer">  
  58.   
  59.         <span id="timer-hours"></span>  
  60.         <span id="timer-minutes"></span>  
  61.         <span id="timer-seconds"></span>  
  62.     </p>  
  63. </div>  
  64.   
  65. </body>  
  66. </html>  

Answers (4)