There are 2 functions for formatting time in PHP: Date () and Gmdate (), as described in the official documentation:
Date--Formatting a local time/date
Gmdate--Formats a GMT/UTC date/time and returns Greenwich Mean Time (GMT).
For example, we are currently in a time zone of +8, so the time that the server runs the following script should return:
The current time is assumed to be 2009-01-04 12:15:27
echo Date (' y-m-d h:i:s ', Time ()); Output is: 2009-01-04 12:15:27
echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2009-01-04 04:15:27
But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2009-01-04 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: 2009-01-04 12:15:27, then in Europe + 2 time zone users see this information published: 2009-01-04 06:15:27, so the time of the message is all right. Reprint please indicate source: PHP in the difference between the date and gmdate function
The above is the PHP date and gmdate function of the difference between the content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!