0

I'm trying to display the current timestamp and refresh every second, doing this with php is too slow and has to reload the page and I know javascript doesn't, I just don't know how to, any help?

<?php
    $time = time() + 3600 * 15;
    echo $time;
?>
<meta http-equiv="refresh" content="0.5;time.php" />

Thanks in advance.

gion_13
  • 41,171
  • 10
  • 96
  • 108
dbut
  • 1
  • 1
  • 1
    But you aren't displaying the current timestamp... you are displaying a timestamp 15 hours in to the future. – Jon Apr 02 '13 at 05:27
  • Because I live in Australia not the server location. – dbut Apr 02 '13 at 05:27
  • javascript will base it off the client's machine, but look [here](http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript) for how to get a timestamp in JS, and look [here](http://www.elated.com/articles/creating-a-javascript-clock/) for how to update a div with the time. (you don't need to worry about the bulk of the script in the second link, just how to update a div value and using `setInterval` – Jon Apr 02 '13 at 05:29
  • Yea I'd suggest as Jon said to use jQuery and setInterval, its really the only good way to do dynamic client side events. Php is oriented at server side processing. – Lemon Drop Apr 02 '13 at 05:37

1 Answers1

0

JavaScript can call up a timestamp based on your local time. Use setInterval to loop and update the timestamp given by Date.now().

setInterval(function() {
    document.getElementById("timestamp").innerHTML = Date.now();
}, 16);

See jsFiddle.

Antony
  • 14,900
  • 10
  • 46
  • 74