简体   繁体   English

Javascript定时循环与PHP

[英]Javascript timed loop with php

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这样做太慢,必须重新加载页面,我知道javascript不会,我只是不知道如何,有什么帮助吗?

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

Thanks in advance. 提前致谢。

JavaScript can call up a timestamp based on your local time. JavaScript可以根据您的本地时间调用时间戳。 Use setInterval to loop and update the timestamp given by Date.now() . 使用setInterval循环并更新Date.now()给定的时间戳。

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

See jsFiddle . 参见jsFiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM