PHP default time zone is Europe and the United States, so with our Chinese time zone a full 8 hours, oh, let me introduce you to the PHP set time zone method, there is a need to know the friends can enter the reference.
In php.ini, the default is Date.timezone = UTC. Change to Chinese time zone, modified to Date.timezone = PRC. If you write the GMT format directly, it is Date.timezone = etc/gmt+8.
Alternatively, you can set it in the PHP page header.
The code is as follows |
Copy Code |
Date_default_timezone_set (' PRC '); |
In PHP5, there are many ways to set or get the default time zone settings, for example, using the Date_default_timezone_setl function to set the time zone
The code is as follows |
Copy Code |
Date_default_timezone_set ("Asia/shanghain"); Set the time zone to Shanghai ?> or set the Tokyo time zone code to: Date_default_timezone_set ("Asia/tokyo"); ?> When the system is initialized, add Ini_set (' Date.timezone ', ' Asia/shanghai '); Or Date_default_timezone_set ("PRC"); |
Will resolve the time zone difference 8
And if you have php.ini administrative privileges can be modified directly in the php.ini OH
To manually modify php.ini settings
Open php found Date.timezone = "PRC" If you have to remove the previous semicolon, no words manually added!
After loading the PHP5 you will find this problem:
The code is as follows |
Copy Code |
$atime =date ("y-m-d h:i:s"); Echo $atime; ?> $atime =date ("y-m-d h:i:s"); Echo $atime; ?>
|
You may find that the output time is not the same as your current time.
The reason is that if you do not set your server local time zone in the program or configuration file, the time taken by PHP is Greenwich Mean time, so there will be a discrepancy with your local time.
Greenwich Mean Time and Beijing time is about 8 hours. So how do we avoid time errors?
Let's take a look at the workaround:
In the header, use Date_default_timezone_set () to set my default time zone to Beijing time.
The code is as follows |
Copy Code |
Date_default_timezone_set (' PRC '); echo Date (' y-m-d h:i:s '); ?>
|
The time is the same as the current time of the server.
Make sure that the H in date (' y-m-d h:i:s ') is uppercase if an Insert database error occurs.
http://www.bkjia.com/PHPjc/631528.html www.bkjia.com true http://www.bkjia.com/PHPjc/631528.html techarticle PHP Default time zone is Europe and the United States, so with our Chinese time zone a full 8 hours, oh, let me introduce you to the PHP set time zone method, there is a need to know the friends can enter the reference. ...