The default time zone of PHP is UTC, while Beijing is located in the GMT + 8, which is eight hours ahead of the UTC time zone. therefore, time () is used in PHP () the current time obtained by the function is always 8 hours different.
The code is as follows:
Date_default_timezone_set ("ETC/GMT-8 ");
$ Tm = time ();
Echo date ("Y-m-d h: I a", $ tm );
Echo"
";
Echo date ("Y-m-D", $ tm );
?>
The default time zone of PHP is UTC, while Beijing is located in the GMT + 8, which is eight hours ahead of the UTC time zone. therefore, time () is used in PHP () the current time obtained by the function is always 8 hours different.
You can configure it in either of the following ways: 1. modify the value of date. timezone in the php. ini file
2. use a function that specifically sets the time zone, date_default_timezone_set ("ETC/GMT-8 ");
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.