Php time zone setting method summary

Source: Internet
Author: User
Php time zone setting method summary

  1. Function_exists (date_default_timezone_set); // at this point, he always returns 1. this function is used to determine whether the character here is a defined function name.
  2. Date_default_timezone_set ("Etc/GMT"); // This is the Greenwich mean time. the obtained time is the same as the default time zone.
  3. Date_default_timezone_set ("Etc/GMT + 8"); // This is 8 hours slower than the standard time of Linwei governance
  4. Date_default_timezone_set ("Etc/GMT-8"); // This is 8 hours faster than Linwei's standard time
  5. Date_default_timezone_set ('prc'); // Set the China time zone
  6. ?>

Function ini_set (): You can add ini_set ('date. timezone ', 'Asia/Shanghai') at the beginning of the file; // 'Asia/Shanghai' is the Shanghai time zone.

Manually modify php. ini settings. open php and find date. timezone = "PRC". if you have removed the semicolon, add it manually!

Some additional information: you will find this problem after installing PHP5.

  1. $ Atime = date ("Y-m-d H: I: s ");
  2. Echo $ atime;
  3. ?>

Output: What time is it now at 06:36:06? /Mine is

The reason is that if you do not set the local time zone of your server in the program or configuration file, the time taken by PHP is the Greenwich mean time, so it may be different from your local time. The GMT standard time is about eight hours behind Beijing time. how can we avoid time errors?

Solution: Use date_default_timezone_set () in the page header to set my default time zone to Beijing time.

  1. Date_default_timezone_set ('prc ');
  2. Echo date ('Y-m-d H: I: s ');
  3. ?>

The time is the same as the current server time! The additional values are used as follows: date_default_timezone_set (PHP 5> = 5.1.0RC1) date_default_timezone_set -- set the default time zone for all date and time functions in a script. description: bool values (string timezone_identifier) values () set the default time zone for all date and time functions. Note: Since PHP 5.1.0 (this version of the DATETIME function has been rewritten), if the time zone does not comply with the rules, every call to the DATETIME function will generate an E_NOTICE-level error message. Timezone_identifier time zone identifier, for example, UTC or Europe/Lisbon. This function returns TRUE forever (even if the timezone_identifier parameter is invalid ). Or modify the value of date. timezone in php. ini to date. timezone = PRC.

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.