开发者

Server Real Time on Website

开发者 https://www.devze.com 2023-01-25 08:44 出处:网络
I would like to grab the time (something like): 16:08 from the server - and display it on the website real time. (Like, each minute do the update, and display the new time.

I would like to grab the time (something like): 16:08 from the server - and display it on the website real time. (Like, each minute do the update, and display the new time.

I'm not sure however, what wou开发者_JS百科ld be a good way for accomplish this nor if there is any nice plugin that I should be aware of. :D

Can I have some insights about the possibilities here?

I'm using PHP and I can use Jquery as library.

Thanks a lot, MEM


Use Javascript and set a timer for every minute. Have the timer call a function that uses Ajax to call the correct page on the time server which gets the time and then have the Javascript replace the existing time.

You could also just get the actual time from the server when you load the page, then use Javascript to increment the minute/hour section appropriately by using a timer that 'ticks' every minute.


If the problem is just to display the time you can use Date.getTime() javascript function. But if you want to get the time from the server and display it to the client you can use an ajax request using JQuery.

0

精彩评论

暂无评论...
验证码 换一张
取 消