PHP class commodity seconds kill timing implementation Code _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.