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

134
Visualizações
countdown timer isn't showing up

I was trying to create a countdown with php and js. I am learning js and php at the moment so I wanted to try and combine these two to make a countdown in which days, hours, minutes and seconds are included. the outcome of this code only tells me till when it runs but not how much time is left, so the countdown itself isn't working. can anyone help?

  <?php 
    $date = date('2022-02-26');
    $time = date('23:59:59');
    $date_today = $date . ' ' . $time;
    echo "it will run till" .$date_today;
    ?>
    <script type="text/javascript">
    //set the date we are counting to
    var count_id = "<?php echo $date_today; ?>";
    var countDownDate = new Date(count_id).getTime();
    //update countdown every second
    var x = setInterval(function(){
    //get today's date and time
    var now = new date().getTime();
    //find the distance between now and countdown 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);
    // output the results in an elemtwith id="demo"
    document.getElementById("demo").innerHTML = days + "d " + hours + "h " + 
    minutes + "m " + seconds + "s ";
    // If the countdown over, write some text
    if(distance<0){
    clearInterval(x);
    document.getElementById("demo").innerHTML="Expired"
    }
    },1000);
    </script><?php
    echo '<p id="demo" style="font-size:30px;"></p>';
    ?>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

var now = new date().getTime();

spelling mistake, it should be

var now = new Date().getTime();

and now it works

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