How does php convert the obtained time to Beijing time?

Source: Internet
Author: User
How does php convert the obtained time to the Beijing time starting from php5.10? the time zone settings are added to php, and the time displayed in php is the Greenwich Mean Time, this caused an eight-hour gap between our users in China! The related setting is to modify the date. timezone parameter in php. ini: [Date]; Definesthedefault php how to convert the obtained time to Beijing time

Since php5.10, the time zone settings have been added to php. the time displayed in php is Greenwich Mean Time, which causes eight hours of downtime for Chinese users!
Modify the date. timezone parameter in php. ini:
[Date]
; Defines the default timezone used by the date functions
; Date. timezone =

It is disabled by default. you only need to remove the comment and change it
[Date]
; Defines the default timezone used by the date functions
Date. timezone = PRC

PRC is the People's Republic of China "!
For other options, refer to the php Manual.
However, the above Asia region missed our capital, Beijing. I don't know if foreigners intentionally did it!

If you do not have the permission to modify php. ini, you only need to call date_default_timezone_set ('prc') when calling the time and date function!
You can also call date_default_timezone_get () to view the current time zone settings!

For XXX, the available values for large regions are:
Asia/Chongqing, Asia/Shanghai, Asia/Urumqi)
Hong Kong and Taiwan regions available: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in sequence: Macao, Hong Kong, and Taipei)
Region: date. timezone = "Asia // Taipei"
Singapore: Asia/Singapore


Solution to eight hours of time difference in PHP5


After installing php5, I accidentally saw someone on the forum saying that php5.1.2 showed a total of eight hours,
??? Echo date ("Y-m-d H: I: s ");
?>
The test result is 8 hours different.
??
?? Later, after finding information on the forum, I finally solved the problem. in php5 and later versions, I had to output local time (limited to China). I can write the code like this:
?? Date_default_timezone_set ('Asia/Shanghai ');
?? Echo date ('Y-m-d H: I: s ');
?>

You can also write the code as follows:
?? Date_default_timezone_set ('Asia/Chongqing ');
?? Echo date ('Y-m-d H: I: s ');
?>
??
In this way, the problem of time difference of eight hours is solved !!~~~

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.