There are two formatting functions for time in PHP: date() and gmdate(). The description in the official documentation is:
date -- format a local time/date
gmdate -- format a GMT/UTC date/time , returned is Greenwich Mean Time (GMT).
For example, the time zone we are in now is +8, then the time returned by the server running the following script should be like this:
The current time is assumed to be 2007-03-14 12:15:27
echo date('Ymd H:i:s ', time()); The output is: 2007-03-14 12:15:27
echo gmdate('Ymd H:i:s', time()); The output is: 2007-03-14 04:15:27
But this is only the result of running PHP under Linux+Apache. If it is run under Windows, the two functions return: 2007-03-14 04:15:27.
Therefore, we should give a compatible way of writing, use gmdate uniformly, and manually set the current time zone. The writing method is improved as follows:
echo gmdate('Ymd H:i:s', time() + 3600 * 8);
This way, no matter what the situation is on Linux + The correct results are obtained under both Apache and Windows. Of course, there is another advantage to writing this way. When the website is for the whole world, the website user only needs to set the time zone, and the program will automatically calculate the time based on the time zone set by the user. The information release time in the database only stores the time generated by the current time(). Then the release time seen in China +8 time zone is: 2007-03-14 12:15:27, then users in Europe +2 time zone see The release time of this information is: 2007-03-14 06:15:27, so the time of the information will all correspond correctly.