The difference between date and gmdate. Read the difference between date and gmdate. There are two formatting functions in PHP: date () and gmdate (), which are described in the official document as follows: date -- format a local time/date gmdate -- format a GMT/UTC date/time, and return the Greenwich Mean Time (GMT ). For example, we are now "> <
The time in PHP has two formatting functions: date () and gmdate (), which are described in the official document as follows:
Date -- format a local time/date
Gmdate -- format a GMT/UTC date/time and return the Greenwich Mean Time (GMT ).
For example, if the current time zone is + 8, the time returned by the server running the following script should be as follows:
The current time is assumed to be 12:15:27
Echo date ('Y-m-d H: I: S', time (); output: 12:15:27
Echo gmdate ('Y-m-d H: I: S', time (); output: 04:15:27
However, this is only the result obtained by running PHP in Linux + Apache. if it is run in Windows, the two functions will return the following results: 04:15:27.
Therefore, we should give a compatibility method, use gmdate in a unified manner, and manually set the current time zone. the improvement is as follows:
Echo gmdate ('Y-m-d H: I: S', time () + 3600*8 );
In this way, both Linux + Apache and Windows get the correct results. of course, this write method also has the advantage that when the website is for the whole world, you only need to set the time zone where the website user is located, the program automatically calculates the time based on the time zone set by the user. the database only saves the time generated by the current time (). the release time displayed in the China + 8 time zone is: 12:15:27, the release time of this information displayed by users in the European + 2 time zone is: 06:15:27, so that all the information time is correct.