Requires the display of a real-time countdown of hours minutes seconds, and the user-side modification date time does not affect the normal display of the countdown (that is, the server time).
In fact, this and a lot of examinations and other systems of time limit function the same requirements.
It is not always possible to use Ajax to get server time every second, so the real-time countdown must be implemented with JavaScript. This is simple, a bunch of examples online.
The problem now is to address the effect of the user-side modification date time on our display.
The solution is to calculate the time between the client and the server, so the problem is solved.
This only needs to run PHP once, and the time of the real-time countdown is synchronized with the server's time.
The theory is synchronous, but the actual test will have a 1 second error. (The specific reason is connected with the speed, the faster the speed, the smaller the error), but this will not affect our requirements above.
Note: The seconds kill time from morning to evening 10 o'clock.
Code is as follows:
Copy CodeThe code is as follows:
The time in PHP is calculated in seconds. JS time is counted in milliseconds
Date_default_timezone_set (' PRC ');
Date_default_timezone_set ("Asia/hong_kong");//region
Configure the active time period for each day
$starttimestr = "08:00:00";
$endtimestr = "22:00:00";
$starttime = Strtotime ($STARTTIMESTR);
$endtime = Strtotime ($ENDTIMESTR);
$nowtime = time ();
if ($nowtime < $starttime) {
Die ("The activity has not started, the activity time is: {$starttimestr} to {$endtimestr}");
}
$lefttime = $endtime-$nowtime; The actual time remaining (seconds)
?>
XX:xx: xx
http://www.bkjia.com/PHPjc/321640.html www.bkjia.com true http://www.bkjia.com/PHPjc/321640.html techarticle requires the display of a real-time countdown of hours minutes seconds, and the user-side modification date time does not affect the normal display of the countdown (that is, the server time). Actually this and a lot of ...