date -- Format a local time/date
gmdate -- Format a GMT/UTC date/time, returning Greenwich Standard Time (GMT).
For example, the time zone we are currently in is +8, so 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('Y-m-d H:i:s', time()); The output is: 2007-03-14 12:15:27
echo gmdate('Y-m-d H:i:s', time()); The output is: 2007-03-14 04:15:27
But this is just the result of running PHP under Linux+Apache. If running under Windows, the 2 functions return both: 2007-03-14 04:15:27.
Therefore, we should give a compatibility writing method, use gmdate uniformly, and manually set the current time zone. The writing method is improved as follows:
echo gmdate('Y-m-d H:i:s', time() + 3600 * 8);
In this way, we get the correct results regardless of Linux+Apache or Windows. Of course, there is another advantage in writing this way. When the website is facing the whole world, the website user only needs to set the time zone where he is located, and the program automatically calculates the time according to the time zone set by the user. The information release time in the database only contains the time generated by the current time(). Then the release time seen in the +8 time zone in China is: 2007-03-14 12:15:27, and the release time of the information when users see this information in the +2 time zone in Europe is: 2007-03-14 06:15:27, so that all the information time corresponds to the correct time.
gmdate -- Format a GMT/UTC date/time, returning Greenwich Standard Time (GMT).
For example, the time zone we are currently in is +8, so 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('Y-m-d H:i:s', time()); The output is: 2007-03-14 12:15:27
echo gmdate('Y-m-d H:i:s', time()); The output is: 2007-03-14 04:15:27
But this is just the result of running PHP under Linux+Apache. If running under Windows, the 2 functions return both: 2007-03-14 04:15:27.
Therefore, we should give a compatibility writing method, use gmdate uniformly, and manually set the current time zone. The writing method is improved as follows:
echo gmdate('Y-m-d H:i:s', time() + 3600 * 8);
In this way, we get the correct results regardless of Linux+Apache or Windows. Of course, there is another advantage in writing this way. When the website is facing the whole world, the website user only needs to set the time zone where he is located, and the program automatically calculates the time according to the time zone set by the user. The information release time in the database only contains the time generated by the current time(). Then the release time seen in the +8 time zone in China is: 2007-03-14 12:15:27, and the release time of the information when users see this information in the +2 time zone in Europe is: 2007-03-14 06:15:27, so that all the information time corresponds to the correct time.