The time in PHP has 2 formatting functions: Date () and Gmdate (), which are 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 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 2007-03-14 12:15:27
echo Date (' y-m-d h:i:s ', Time ()); Output is: 2007-03-14 12:15:27
echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2007-03-14 04:15:27
But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2007-03-14 04:15:27.
Therefore, we should give a compatibility of the wording, the unified use of gmdate, the wording improved as follows:
echo gmdate (' y-m-d h:i:s ', time () + 3600 *;
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: 2007-03-14 12:15:27, then in Europe + 2 time zone users see this information published: 2007-03-14 06:15:27, the time for this information is all right.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.