The time obtained by date () in php5 is not the solution of the current time

Source: Internet
Author: User
The time obtained by date () in php5 is not the solution of the current time

  1. [Date]
  2. ; Defines the default timezone used by the date functions
  3. ; Date. timezone =

It is disabled by default. you only need to remove the comment and change it

  1. [Date]
  2. ; Defines the default timezone used by the date functions
  3. Date. timezone = PRC

PRC is the People's Republic of China "! For other options, refer to the php Manual. The Asia region missed Beijing and MGB.

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 regions in large regions are: Asia/Chongqing, Asia/Shanghai, and Asia/Urumqi (which are re-built, Shanghai, and zookeeper in sequence) hong Kong and Taiwan region availability: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in sequence: Macao, Hong Kong, and Taipei). The region can be set to date. timezone = "Asia // Taipei" and Singapore: Asia/Singapore

Appendix: Solution to eight hours of time difference in PHP5: php5.1.2 shows a total of eight hours,

  1. Echo date ("Y-m-d H: I: s ");
  2. ?>

The test result is 8 hours different.

In the original version of php5 and later versions, to export the local time (limited to China), you can refer to the following syntax:

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

This is also possible:

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

Let's see the wonderful result: the problem of time difference of eight hours has been solved successfully.

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.