Incorrect phpdate () function output date solution. If you use php for the first time, you may find that the date is 8 hours related to the correct date when you use the phpdate function to output the date after configuring the php environment. For example, if you copy the following code and use php for the first time, you may find that the date is 8 hours related to the correct date when you use the php date function to output the date after configuring the php environment.
Example
| The code is as follows: |
|
Echo date ('Y-m-d H: I: s '); ? > 〉 |
Output Current time: 02:32:17
The actual time is 10:32:17.
Is it because the date () time in PHP is incorrect and 8 hours less?
Let's take a look at the "Example 1. date () example" in the PHP Manual. The first line has a time zone setting.
// Set the default time zone to use. Available in PHP 5.1
| The code is as follows: |
|
Date_default_timezone_set ('utc '); |
Php. date is added to ini. the timezone option is disabled by default, that is, the displayed time (no matter what php command is used) is Greenwich Mean Time, which is exactly eight hours behind Beijing time.
How can I set the correct PHP time?
1. modify php. ini. Open php. ini to search for date. timezone and remove the semicolon = followed by Asia/Shanghai. restart the apache server. The disadvantage is that if the program
Put it on someone else's server. you cannot modify php. ini. we can modify the php program.
| The code is as follows: |
|
Date_default_timezone_set ('Asia/Chongqing '); Echo date ('Y-m-d H: I: s '); ?>
|
Add 8 hours of seconds.
| The code is as follows: |
|
Echo date ("Y-m-d H: I: s", time () + 8*60*60 ); ?> |
When the date function outputs a date, it will find that the date is related to the correct date for 8 hours. The sample code is as follows...