Solution to the 8-hour time difference between the date function and Beijing in php5

Source: Internet
Author: User
Tags what php
& Nbsp; Beijing time is in Zone 8, which may be due to time zone issues. but it was okay before. after google found that php started from php5.1.0. date is added to ini. the timezone option is disabled by default: php function date (& quot; Y-n-dH-I-s & quot ;); the output time is 8 hours different from the local time. solution: Beijing time is East 8, maybe Beijing time is East 8, maybe it is time zone. but it was okay before. after google found that php started from php5.1.0. date is added to ini. timezone is disabled by default.

Problem:

Php function date ("Y-n-d H-I-s"); the output time is 8 hours different from the local time.

Solution

Beijing time is East 8, which may be due to time zone issues. but it was okay before. after google found that php started from php5.1.0. date is added to ini. the timezone option is disabled by default, that is, the displayed time (no matter what php command is used) is the Greenwich mean time, and our time (Beijing time) the difference is exactly 8 hours.

Set the time zone before calling the date () function.

Method 1:
Date_default_timezone_set ('prc ');
No return value. Now we can use the date function directly.
$ Time = date (Y. "year". m. "month". d. "day". G. "hour". I. "minute ");

Method 2:
In php. ini, modify date. timezone = to date. timezone = "Asia/Shanghai" (or change to date. timezone = PRC), remove the semicolon, and 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.