PHP Tutorial System time zone 8-hour difference setting method
There are two ways to modify the PHP system time zone:
1. Modify the settings in the php.ini file, locate ";d ate.timezone=" under [Date], modify the entry to Date.timezone=asia/hong_kong (PRC time in China), and then restart the Apache server.
2. In the application, add the "Date_default_timezone_set (" Asia/hong_kong ") function before using the time-date function
To get local time after modifying the php.ini file:
PHP Code:
echo "is now Beijing time:". Date ("Y-m-d h:i:s"). "
”;
?>
Show Results:
It's Beijing time: 2010-11-30 20:50:03 (in accordance with local time)
PHP.ini the modified code:
[Date]
; Defines the default timezone used by the date functions
; Http://php.net/date.timezone
Date.timezone = PRC
Here's a look at more ways
1. Modify the settings in the php.ini file.
[Date]
Defines the default timezone used by the date functions
Date.timezone = Asia/shanghai
It's really ... You can set Shanghai,chongqin,hong_kong,taibei ... Wait, but just did not find Beijing, do not know what is the reason.
2. Run-time settings in the PHP program.
if (Date_default_timezone_get ()! = "1asia/shanghai") Date_default_timezone_set ("Asia/shanghai");
?>
Note: There is a 1 in the time settings obtained with "Date_default_timezone_get", and it is not clear that it is a miscellaneous matter.
3. In the use of time, the extra 8*3600 second is also a drop.
echo Date ("Y-m-d h:i:s", Time () +8*3600);
?>
Note:
Starting with php5.0, it takes 8 hours less time to get the system time in PHP than the current time. The reason is that PHP is used UTC time when TimeZone is not set in php.ini, so the time in China is less than 8 hours
http://www.bkjia.com/PHPjc/632304.html www.bkjia.com true http://www.bkjia.com/PHPjc/632304.html techarticle PHP Tutorial System time zone 8-hour difference setting method to modify the PHP system time zone two ways: 1, modify the settings in the php.ini file, find [Date], date.timezone=, change the item to date ...