Home >Backend Development >PHP Tutorial >php date reads incorrect time_PHP tutorial
php date reading time is incorrect
$DateTime = date("Y-m-d H:i:s");
echo $DateTime;
Why is the printed date inconsistent with the system time of my server? I'm testing it locally.
Configure php.ini
You can also set it directly to East Eighth District in php.ini:
Open php.ini and search for date.timezone. Remove the semicolon in front of it, add Asia/Shanghai after =, and restart apache
Set in the program
@ini_set('date.timezone','PRC');
$DateTime = date("Y-m-d H:i:s");
echo $DateTime;
That's it. Add @ini_set('date.timezone','PRC'); above to change the configuration time zone.