使用网页上的时钟服务器和系统时间? [英] Clock on webpage using server and system time?

查看:394
本文介绍了使用网页上的时钟服务器和系统时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个时钟添加到网页。时钟需要与服务器同步,但我真的不希望有它不断地检查服务器的页面将在多台电脑每天24小时开放。有没有一些方法来从服务器获取时间,然后使用系统时钟,随时更新,并检查服务器每15分钟左右,以保持同步?

I need to add a clock to a web page. The clock needs to be synchronized with a server but I really don't want to have it constantly check the server as the page will be open 24/7 on several PCs. Is there some way to get the time from the server and then use the systems clock to keep it updated and check the server every 15 minutes or so to keep it synced?

推荐答案

我已经走了这个之前是这样的:

The way I've gone about this before is:

  • 走的时候从服务器,
  • 走的时候从客户端(立即)
  • 在得到补偿。
  • 当表示时钟,应用偏移到当前时间在客户机上。

您只需从服务器偶尔更新此。

You only need to update this occasionally from the server.

这是你要弄清楚,虽然现在的问题是,在作出请求,从服务器的时候,会有一个滞后,才能获得客户端的时间。您可以通过使用Ajax请求来获取服务器的时间,没有别的,从而节省开销,网络延迟等可能减少这一点。

The problem that you've got to sort out though is that in making a request to get the time from the server, there will be a lag before you can get the client time. You can probably minimize this by using an ajax request to get the server time and nothing else, thereby cutting overhead and network lag etc.

这篇关于使用网页上的时钟服务器和系统时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆