A friend who used PHP for the first time may find that when we configure the PHP environment, we use the PHP date function to output the date and find that the date is related to the correct date for 8 hours.
Cases
| The code is as follows |
Copy Code |
echo Date (' y-m-d h:i:s '); ?〉 |
Output Current time: 2008-10-12-02:32:17
Strange, the actual time is: 2008-10-12-10:32:17
is PHP date () 8 hours less than the correct time?
Take a look at the PHP manual "Example 1." Date () example "The first line has one more time zone set
Set the default time zone to use. Available from PHP 5.1
| The code is as follows |
Copy Code |
Date_default_timezone_set (' UTC '); |
Originally php5.1. Start, PHP.ini added date.timezone this option, by default, is closed, that is, the time displayed (no matter what PHP command) is Greenwich Mean Time, and Beijing time is just 8 hours.
How to set up to get the correct PHP time?
1, modify the php.ini. Open php.ini Find Date.timezone Remove the preceding semicolon = add Asia/shanghai After, restart Apache server can--the disadvantage is that if the program
Put on someone else's server, can't modify php.ini, we can modify the PHP program OH
| The code is as follows |
Copy Code |
Date_default_timezone_set (' asia/chongqing '); echo Date (' y-m-d h:i:s '); ?>
|
Directly plus 8 hours of seconds
| The code is as follows |
Copy Code |
echo Date ("Y-m-d h:i:s", Time () +8*60*60); ?> |
http://www.bkjia.com/PHPjc/632080.html www.bkjia.com true http://www.bkjia.com/PHPjc/632080.html techarticle a friend who used PHP for the first time may find that when we configure the PHP environment, we use the PHP date function to output the date and find that the date is related to the correct date for 8 hours. Example code to copy code as follows ...