Home>Article>Backend Development> What should I do if the time output by the date() function in PHP is inconsistent with Linux?
What should I do if the time output by the date() function in PHP is inconsistent with the Linux time? How to deal with it? The following article will introduce you to the solution. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
Cause: Use PHP to get the time and find that the time is wrong. This is because the default time zone of PHP is UTC, Universal Time Coordinated (UTC). The solution is to set the time to Beijing time.
1. Modify the php.ini file
1. Open the php.ini file
2. Search for date.timezone and find; date.timezone =
3. Change it todate.timezone ="PRC"
. If there is a semicolon on the left side of date.timezone, remove the semicolon
4. Restart php
service php-fpm restart
2. Use date_default_timezone_set('') method
Add the following code at the beginning of the php program
For more related knowledge, please pay attention toPHP中文网! !
The above is the detailed content of What should I do if the time output by the date() function in PHP is inconsistent with Linux?. For more information, please follow other related articles on the PHP Chinese website!