Home > Backend Development > PHP Tutorial > Three implementation methods of PHP real-time countdown_PHP tutorial

Three implementation methods of PHP real-time countdown_PHP tutorial

WBOY
Release: 2016-07-13 10:31:40
Original
949 people have browsed it

Requirements:

1. There must be a real-time countdown display of hours, minutes and seconds. ​

2. Modifying the date and time on the client side will not affect the normal display of the countdown (that is, the server time shall prevail). In fact, this is the same as the requirements for system time limit functions such as many exams. ​

Solution:

1. You can’t use ajax to get the server time every second, so the real-time countdown must be implemented with javascript. This is very simple, there are a lot of examples on the Internet. ​

2. The problem now is to solve the impact of the date and time modified by the client on our display. The solution is to calculate the time difference between the client time and the server time, so that the problem is completely solved. You only need to run php once, and the real-time countdown time will be synchronized with the server time. The theory is synchronous, but the actual test will have an error of 1 second (the specific reason is related to the network speed. The faster the network speed, the smaller the error), but this will never affect our above requirements. ​

" 09:00:00"; $endtimestr = "18:30:00"; $starttime = strtotime($starttimestr); $endtime = strtotime($endtimestr); $nowtime = time(); $lefttime = $endtime-$ nowtime;//Actual remaining time (seconds)?> 

Code 2, modified some bugs in code 1:  

Code 3, different ideas, much simpler:

http://www.bkjia.com/PHPjc/762036.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/762036.htmlTechArticleRequirements: 1. There must be a real-time countdown display of hours, minutes and seconds. 2. Modifying the date and time on the client side will not affect the normal display of the countdown (that is, the server time shall prevail). Actually this...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template