Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

122
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda