In php. ini, the default value is date. timezone = UTC. Change to China time zone and date. timezone = PRC. If the GMT format is directly written, it is date. timezone = Etc/GMT + 8.
You can also 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 obtain the default time zone settings. For example, you can use the date_default_timezone_setl function to set the time zone.
The code is as follows: |
Copy code |
<? Php Date_default_timezone_set ("Asia/Shanghain"); // Set the time zone to Shanghai. ?> Or set the Tokyo time zone code: <? Php Date_default_timezone_set ("Asia/Tokyo "); ?> When the system is initialized, add Ini_set ('date. timezone ', 'Asia/Shanghai '); Or Date_default_timezone_set ("PRC "); |
The time zone difference is 8.
If you have php. ini management permissions, you can directly modify them in php. ini.
Manually modify php. ini settings
Open php and find date. timezone = "PRC". If the semicolon is removed, add it manually!
After installing PHP5, you will find the following problems:
The code is as follows: |
Copy code |
<? Php $ Atime = date ("Y-m-d H: I: s "); Echo $ atime; ?> <? Php $ Atime = date ("Y-m-d H: I: s "); Echo $ atime; ?>
|
You may find that the output time is different from the current time.
The reason is that if you do not set the local time zone of your server in the program or configuration file, the time taken by PHP is the Greenwich mean time, so it may be different from your local time.
The GMT standard time is about eight hours behind Beijing time. How can we avoid time errors?
Let's take a look at the solution:
Use date_default_timezone_set () in the header 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.
If a database insertion error occurs, make sure that H in date ('Y-m-d H: I: s') is in uppercase.