Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

119
Views
Need to add 30 minutes timer into if condition using Js

I have ecommerce website. In that for same day delivery need to order before 11. So before 30 minutes of the end time(i.e. 11) i want to show that timer section. Below code I am trying But getting issue how to set timer functionality.

setInterval(function(){
    var secs = 1800;
    var date = new Date;
    // date.setTime(result_from_Date_getTime);

    var seconds = date.getSeconds();
    var minutes = date.getMinutes();
    var hour = date.getHours();

    console.log("Hour"+hour+"Minutes"+minutes+"seconds"+seconds);
    // console.log(minutes);
    // console.log(seconds);
    if(hour == 10 &&    minutes>=30)
    {
        var mins = secs / 60;
        console.log("Timer"+mins);
        $('.top-header-content1').removeClass('hide-ticker1');
        
    }
    
    else if (hour >= 11){
        console.log("hii11");
        $('.top-header-content1').addClass('hide-ticker1'); 
    }
    secs--;
    },1000);

If anyone have a idea , how to add time please let me know

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Hi you use this code below:

 /// the counting date
var countDownDate = new Date("Jan 5, 2024 15:37:25").getTime();

// Update the count down every 1 second
var x = setInterval(function() {

  // Get today's date and time
  var now = new Date().getTime();

  // Find the distance between now and the count down date
  var distance = countDownDate - now;

  // Time calculations for days, hours, minutes and seconds
  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);

  // Display the result in the element with id="demo"
  document.getElementById("demo").innerHTML = days + "d " + hours + "h "
  + minutes + "m " + seconds + "s ";

  // If the count down is finished
  if (distance < 0) {
    clearInterval(x);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);
<p id="demo"></p>

about 4 years ago · Juan Pablo Isaza Report

0

The following code will start a setInterval() in which during a time window between 10:30h and 11:00h a countdown will be shown. Before 10:30h and after 11:00h different messages are shown. And after 11:00h the setInterval is cleared.

// div for output on page:
const demo=document.getElementById("demo"),
// today's date
      today = new Date();
today.setHours(11);today.setMinutes(0);today.setSeconds(0);
today.intv=setInterval(checkTime,1000);

function checkTime(){
  const now=new Date();
  if (now>today) {
    demo.textContent="Order today for tomorrow's delivery.";
    clearInterval(today.intv);
  }
  else if (now>(today-1800000)){
    let tsec=Math.floor((today-now)/1000),
        sec=tsec%60,
        min=(tsec-sec)/60;
    
    demo.textContent=`${min} minutes and ${sec} seconds left if you want to order for today's delivery.`;
  } else 
    demo.textContent="Order now for today's delivery!"
}
<p id="demo"></p>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!