Home > Article > Backend Development > Solution to the wrong time obtained by php
Solution to php getting the wrong time: First open the "php.ini" file; then look for the "date.timezone" item; finally modify it to "date.timezone = "PRC"" and save it .
Recommended: "PHP Video Tutorial"
PHP date() gets the system time incorrectly:
Using PHP to obtain the system time, I found that the time was wrong because the default time zone of PHP is UTC, and its time zone should be set to Beijing time.
Method 1: Modify the php.ini file
Open the php.ini file: left-click the WampServer icon in the lower right corner - PHP - php.ini,
Search for date.timezone, find date.timezone="UTC",
Change it to date.timezone="PRC", if there is a semicolon on the left side of date.timezone, remove the semicolon.
<span class="cur_time"><?php echo "当前时间:" . date("Y-m-d H:i:s") ?></span>
Method 2: Use date_default_timezone_set(”) method;
<?php date_default_timezone_set('PRC'); echo date("Y-m-d H:i:s"); ?>
The above is the detailed content of Solution to the wrong time obtained by php. For more information, please follow other related articles on the PHP Chinese website!