Date_default_timezone_set () Setting the time zone method in PHP

Source: Internet
Author: User
Date_default_timezone_set () Setting the time zone

<?phpecho function_exists (date_default_timezone_set). " <br> ";//In this he always returns 1, this function is to determine if the character inside this is a defined function name, echo date (' y-m-d h:i:s ')." <br> ";///The time of the default time zone echo date_default_timezone_set (" Etc/gmt ")." <br> ";//This is Greenwich Mean time, and the time to get is the same as the default time zone, Echo date (' y-m-d h:i:s ')." <br> "; Echo date_default_timezone_set (" Etc/gmt+8 ")." <br> ";//This is 8 hours slower than Linwei Standard time echo date (' y-m-d h:i:s ')." <br> "; Echo date_default_timezone_set (" Etc/gmt-8 ")." <br> ";//from the last can not be difficult to imagine, we 8 hours faster than that, so minus 8echo date (' y-m-d h:i:s ')." <br> "; Echo date_default_timezone_set (' PRC ')." <br> "; Set the Chinese time zone echo date (' y-m-d h:i:s '). <br> "//China Standard time? >//output 12009-05-15 02:20:42//default time zone time 12009-05-15 02:20:42//(" ETC/GMT ") Greenwich Mean Time 12009-05-14 18:20:42//("Etc/gmt+8") is 8 hours slower than Linwei standard Time 12009-05-15 10:20:42//("etc/gmt-8") 8 hours faster than Linwei standard Time, is our Beijing time 12009-05-15 10:20:42/ /(' PRC ') China standard Time 


before a legacy problem, echo Date ("Y-m-d h:i:s", Time ()) is always back with the actual time, and today finally found the reason and solution on the Internet, share the following:

I add that I follow the method suggested below to modify php.ini can not find Date.timezone this line, is not there is no way, of course, no, haha no words on their own add, own hands and clothing. I added such a sentence Date.timezone = "PRC", the problem is done, happy.

Starting with php5.1.0, PHP.ini has added Date.timezone, which by default is

, which is the time to display (no matter what PHP command) is Greenwich Mean Time

And our Time (Beijing time) The 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 the version of

2, if it is necessary, and can not modify php.ini, you need to initialize the time on the statement of the
above add Date_default_timezone_ Set (XXX);
CP does not have this problem

3, once and for all, can only modify php.ini. Open php.ini Find Date.timezone Remove the preceding semicolon
= followed by xxx, restart the HTTP service (such as Apache2 or IIS, etc.)

about XXX, mainland China available values are: asia/chongqing, Asia/shanghai, Asia/urumqi (Chongqing, Shanghai, Urumqi, respectively)
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macao, Hong Kong, Taipei)
Singapore: Asia/singapore
Foreigners seem to have leaked Beijing
other available values are: Etc/gmt-8, Singapore, Hongkong, PRC
PRC? PRC is the People's Republic of China Ah-_-

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.