It is required to display a real-time countdown of hours, minutes and seconds. Modifying the date and time on the client side will not affect the normal display of the countdown (that is, based on the server time).
In fact, this is the same requirement as the time limit function of many exam and other systems.
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.
The problem now is to solve the impact of the user-side modified date and time on our display.
The solution is to calculate the time difference between the client time and the server time, so that the problem is solved.
In this way, you only need to run php once, and the real-time countdown time will be synchronized with the server time.
The theory is synchronization, but there will be an error of 1 second in actual testing. (The specific reason is related to the Internet speed. The faster the Internet speed, the smaller the error.) But this will never affect our above requirements.
Note: Flash sale time is from morning to 10pm.
Code is as follows: