PHP5.2 the date () function shows a 8-hour difference between time and Beijing _php tips

Source: Internet
Author: User

Problem:

PHP function Date ("y-n-d h-i-s"); The output time differs from local time by 8 hours.

Solving ideas

Beijing time is East 8, it may be a time zone problem. But before the problem ah, after Google found that originally from php5.1.0, PHP.ini added date.timezone this option, by default is closed, That is, the time shown (no matter what PHP command) is Greenwich Standard Time, and our time (Beijing time) is bad 8 hours.

The time zone is set before the date () function is called.

Method One:
Date_default_timezone_set (' PRC ');
no return value. Let's just use the date function directly below OK
$time = Date (Y.) Year ". M." Month ". D." Day. " G. " When ". I." Points ");

Method Two:

Modify php.ini = Date.timezone = Date.timezone = "Asia/shanghai" (or change to Date.timezone = PRC) and remove the preceding semicolon, restart Apache.

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.