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

188
Views
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 answers
Answer question

0

replace this with your Clock.php file content:

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