Solution when the time obtained in PHP is inconsistent with the local time

Source: Internet
Author: User
Use "date (Y-m-dH: I: s)" in PHP to obtain the real time difference between the time and the local time. the specific time zone setting solution

Use "date (Y-m-d H: I: s)" in PHP to obtain the real time difference between the time and the local time. the specific time zone setting solution:
1. the default time zone in the configuration file of php. ini is not modified to the current time zone location (if you have the permission to modify php. ini)
Solution: modify php. ini and set "date. timezone" to "date. timezone = Asia/Shanghai"
For other parameters, refer to the PHP Manual.

2. the time zone is not initialized in the program.
Solution: add the following program in the global configuration.
 

PHP code
  1. $ Timezone = "Asia/Shanghai ";
  2. If (PHP_VERSION> = '5. 1 '&&! Emptyempty ($ timezone ))
  3. {
  4. Date_default_timezone_set ($ timezone );
  5. }

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.