用php服务器时间设置Javascript时间? [英] Set Javascript time with php server time?
问题描述
我有一种情况,我希望服务器时间显示在网页上。
目前我保持简单,只需这样做
I have a situation where I want the server time to be displayed on a web page. At present I keep it simple and just do this
<?php
$CTIME=date ("g:i a");
?>
这很好用 - 除非我更喜欢它,如果它自己更新而不需要刷新页面。我想也许有一种方法我可以用PHP脚本设置javascript时间函数 - 但是我不知道如何做到这一点。
This works great- except I would prefer it if it updated by itself without the need to refresh the page. I was thinking perhaps there is a way I can set the javascript time function with the time from a php script- but I've got no idea as to how I could go about doing this.
也许我正在考虑这个错误...也许还有其他解决方案我没有想到,任何想法?
Perhaps I'm thinking about this wrong... maybe there is another solutions I'm not thinking of, Any ideas ??
推荐答案
试试这个:
<javascript>
var ctime = '<?php echo date ("g:i a"); ?>';
</javascript>
然后让计时器增加javascript端的值。这不是很精确,但是如果我看到了你只需要几分钟而不是几秒钟,那么精确度可能不是问题。
Then let a timer increase the value on the javascript side. It's not very precise, but if I saw that right you need minutes only, not seconds, so precision is probably not an issue.
这篇关于用php服务器时间设置Javascript时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!