SoFunction
Updated on 2025-04-09

What to do if the Date acquisition time is incorrect in PHP

When I used echo $showtime=date("Y-m-d H:i:s") to obtain the system time, I found that the obtained time does not match the system time.

After some research, we found that the default time set by PHP is based on the Greenwich time zone, so we must change the PHP time zone setting to Beijing time.

Operation method:

Open the file, usually in the PHP installation root directory
Find one;
Delete the previous semicolon and change it to = PRC
Save the disk and restart the Apahce service (sometimes there will be problems using Apache's restart function, it is recommended to stop first and then start)
Let's re-check echo $showtime=date("Y-m-d H:i:s").

Is time back to normal?