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

193
Visualizações
How to get server time with JS AND PHP?

I am creating a site where I get the time from the server in php and then pass it to a JS variable, this to perform some other actions.

This is my example of what I have:

Clock.php file: In this file I get the server time

<?php 

echo $s = date('Y-m-d h:i:s');

?>

Index.php file: In this file I get the result of the echo set in the file clock.php.

    <?php include("reloj.php"); ?>
    <input type="text" id="serverDate" style="opacity: 20;" >
<script>
    let reloj = document.getElementById("serverDate");
    
    function muestraReloj () {
            fetch("reloj.php")
            .then(response => response.text())
            .then(data => reloj.value = data); 
                console.log(reloj.value);
           var fechaYHora = new Date(reloj.value).toLocaleTimeString();
            console.log(fechaYHora);
    }
    setInterval(muestraReloj, 1000)
</script>

Everything works correctly for me, but I don't want to show the time that is printed in the echo of the clock file, in the example that I establish if I remove the echo then it fails because it does not show anything. The input with the id serverDate I can hide it but the echo of the file clock.php I don't know how it could be hidden, any ideas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

replace this with your Clock.php file content:

<?php
    echo $_SERVER['REQUEST_TIME'];
?>
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