PHP php.ini time Zone Setup issues

Source: Internet
Author: User
PHP php.ini time Zone Setup issues

2009-09-10 15:40

From php5.1.0 onwards, PHP.ini added date.timezone this option, by default, is closed, that is, the time displayed (no matter what the PHP command) is Greenwich Mean time, and our time (Beijing time) difference is exactly 8 hours, there are the following 3 methods can restore normal time.
1, the simplest way is not to use php5.1 above version;
2, if you want to use more than 5.1 version, and do not modify php.ini, you need to be on the initialization of the time of the statement with Date_default_timezone_set (XXX), or use the date (' y-m-d g:i:t ', Strtotime ( ' +8hour ')) to obtain the date and time;
3, once and for all, can only modify php.ini. Open the php.ini to remove the semicolon in front of the date.timezone, add xxx after =, restart the HTTP service (such as Apache2 or IIS, etc.).
For XXX, the values available in mainland China are: asia/chongqing, Asia/shanghai, Asia/urumqi (Chongqing, Shanghai, Urumqi, respectively), Taiwan available: asia/maca*, Asia/hong_kong, asia/ Taipei (Macau, Hong Kong, Taipei) and Singapore: Asia/singapore, the above is not Beijing, but then look down, the other available values are: Etc/gmt-8,singapore, HONGKONG,PRC. What is PRC? PRC is the People's Republic of China Ah! (This is the Beijing-China Bar) The above is the official PHP file in the GMT-8 of the area below, there may be omissions, if necessary in the official documents to check the better:

Today, when using date ("H:i:s") under PHP5, it is found that the time of the parameter "H" is not the same as the time under window. Check the information, found that it is PHP5 php.ini the default setting is:

[Date]
; Defines the default timezone used by the date functions
;d Ate.timezone =

As a result, GMT time is the default time. And we generally use Beijing time, can be set to: Date.timezone = PRC or Date.timezone = Asia/shanghai. That

[Date]
; Defines the default timezone used by the date functions
Date.timezone = Asia/shanghai

Remember not to set as "asia/beijing", foreigners as if the point of interest in Shanghai, hehe.

If you do not have permission to change php.ini, you can use the function date_default_timezone_set (' PRC '), or Date_default_timezone_set (' Asia/shanghai ');

This function is used to set the default time zone for all datetime functions. This is stated in the manual: "since PHP 5.1.0 (This version date Time function is rewritten), if the time zone is not the rule each call to a DateTime function will produce an E_notice level error message." However, this function returns TRUE forever, even if

Learn more about the function here: string

The return value of this function follows the following order: 1: Use the TZ environment variable (if not empty). 3:date.timezone configuration options (if set). 4: Self-conjecture (if operating system supports). 5: If none of the above selections are successful, return

Go further and learn what UTC is:
Coordinated Universal Time (UTC):
A time-of-compromise, called the coordinated world, was unveiled in 1972. In order to ensure that the world is coordinated with the world Time (UT1) is not more than 0.9 seconds, if necessary, in the coordinated world time to add positive or negative leap seconds. As a result, there are several integer seconds differences between coordinated Universal time and International Atomic Time (TAI). The International Earth Rotation Service Central Bureau (IERS) in Paris is responsible for deciding when to join leap seconds.

UTC = coordinated Universal time. The Chinese name is coordinated world time.

GMT = Greenwich Mean time. When the Chinese name is Greenwich (FLAT) (Here the "w" is not pronounced, and "Green" to read "Gren")

UTC = GMT +/-0.9 s
Therefore, a "leap second" is required to control the difference between UTC.

Php5.1x time zone problem results in a difference of eight hours! Collection
Starting with php5.10, the time zone setting is added to PHP, and the times shown in PHP are Greenwich Mean time, which results in a eight-hour problem for our users in China!
The related setting is to modify the Date.timezone parameter in php.ini:
[Date]
; Defines the default timezone used by the date functions
;d Ate.timezone =

The default is off, just remove the comment, you can
[Date]
; Defines the default timezone used by the date functions
Date.timezone = PRC

Where PRC is the "People's Republic"!
Other options refer to the PHP manual.
However, the above-mentioned Asian region has missed our capital Beijing, do not know that foreigners are not intentional!

If the php.ini permission is not modified, simply call the Date_default_timezone_set (' PRC ') when calling the time-date function!
You can also call Date_default_timezone_get () to view the current time zone settings!

For xxx, big?? The values that are available to you are:
Asia/chongqing, Asia/shanghai, Asia/urumqi (in turn, Shanghai,?? Wood?)
Hong Kong and Taiwan Land available: Asia/macao, Asia/hong_kong, Asia/taipei (Australia, Hongkong, Taipei)
What is the area of Taiwan? : Date.timezone = "Asia//taipei"
? Singapore: Asia/singapore

This article from Csdn Blog, reproduced please indicate the source: http://blog.csdn.net/keenx/archive/2006/03/21/631432.aspx

Excerpt from Dedecms:p hp5 time zone settings
if (php_version > ' 5.1 ') {
$time Wuyi = ' etc/gmt '. ($cfg _cli_time > 0? '-': ' + '). ABS ($cfg _cli_time);
Function_exists (' Date_default_timezone_set ')? @date_default_timezone_set ($time 51): ";
}

If PHP version is greater than 5.1 execute
$cfg _cli_time = 8; 8 hours less! After formatting, set with Data_default_timezone_set ("Etc/gmt+8")!!
Beijing time zone should be etc/gmt+8

Time zone settings are generally set to + 8 hours!
Greenwich Mean Time (GMT)
$date = Gmdate ("y-m-d h:i:s", Time () +8*3600)
Just add 8 hours to the meeting! Write a function or something. Just whatever.

  • Related Article

    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.