Time in PHP has 2 formatting functions: Date () and Gmdate ()
The date () function formats the local date and time and returns the formatted date string. Gmdate--Formats a GMT/UTC date/time and returns Greenwich Mean Time (GMT).
The Gmdate () function formats the GMT/UTC date and time and returns the formatted date string.
For example, we are now in the time zone is +8, then the server run the following script to return the time should be this:
The current time is assumed to be 2017-07-11 12:15:27
echo Date (' y-m-d h:i:s ', Time ()); Output is: 2017-07-11 12:15:27
echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2017-07-11 04:15:27
But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2017-07-11 04:15:27.
Therefore, we should give a compatibility of the wording, unified use of gmdate, and manually set the current time zone, the following improvements:
echo gmdate (' y-m-d h:i:s ', time () + 3600 * 8);
So no matter under the Linux+apache or windows are getting the correct results, of course, there is a benefit to write, when the site is facing the world, then the site users as long as the settings in the time zone, the program automatically based on the time zone set by the user to calculate, The publication time of the information in the database is only the time that is generated by the current date (), then the published time in China + 8 time zone is: 2017-07-11 12:15:27, then in Europe + 2 time zone users see this information published: 2017-07-11 06:15:27, the time for this information is all right.