Php Tutorial System Time Zone 8 time difference Setting Method
You can modify the time zone of the php System in either of the following ways:
1. Modify php. in the INI file, locate "; date." in [date. timezone = ", change this item to date. timezone = asia/hong_kong (prc China time), and then restart the apache server.
2. In the application, add the "date_default_timezone_set (" asia/hong_kong ")" function before using the time and date function.
Modify the php. ini file and obtain the local time:
Php code:
<? Php
Echo "Now Beijing time:". date ("y-m-d h: I: s"). "<p> ";
?>
Display result:
It is now Beijing Time: 20:50:03 (consistent with the local time)
Php. ini modified code:
[Date]
; Defines the default timezone used by the date functions
Http://php.net/date.timezone
Date. timezone = prc
Next let's take a look at more methods
1. Modify the settings in the php. ini file.
[Date]
// Defines the default timezone used by the date functions
Date. timezone = asia/shanghai
This is really... You can set shanghai, chongqin, hong_kong, taibei... and so on, but beijing is not found. I don't know why.
2. runtime settings in the php program.
<? Php
If (date_default_timezone_get ()! = "1 asia/shanghai") date_default_timezone_set ("asia/shanghai ");
?>
Note: There is a 1 in the time setting obtained with "date_default_timezone_get". It is not clear that it is a miscellaneous.
3. When using the time, you can add 8*3600 seconds.
<? Php
Echo date ("y-m-d h: I: Seconds", time () + 8*3600 );
?>
Note:
From php5.0, when you use php to obtain the system time, the time is 8 hours less than the current time. The reason is that when timezone is not set in php. ini, php uses utc time, so it takes 8 hours in China.