PHP System Time Zone 8 time difference Setting Method

Source: Internet
Author: User

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.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.