Incorrect phpdate () function output date solution _ PHP Tutorial

Source: Internet
Author: User
Incorrect phpdate () function output date solution. If you use php for the first time, you may find that the date is 8 hours related to the correct date when you use the phpdate function to output the date after configuring the php environment. For example, if you copy the following code and use php for the first time, you may find that the date is 8 hours related to the correct date when you use the php date function to output the date after configuring the php environment.

Example

The code is as follows:

Echo date ('Y-m-d H: I: s ');
? > 〉

Output Current time: 02:32:17
The actual time is 10:32:17.

Is it because the date () time in PHP is incorrect and 8 hours less?

Let's take a look at the "Example 1. date () example" in the PHP Manual. The first line has a time zone setting.
// Set the default time zone to use. Available in PHP 5.1

The code is as follows:

Date_default_timezone_set ('utc ');

Php. 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 Greenwich Mean Time, which is exactly eight hours behind Beijing time.

How can I set the correct PHP time?

1. modify php. ini. Open php. ini to search for date. timezone and remove the semicolon = followed by Asia/Shanghai. restart the apache server. The disadvantage is that if the program

Put it on someone else's server. you cannot modify php. ini. we can modify the php program.

The code is as follows:


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


Add 8 hours of seconds.

The code is as follows:

Echo date ("Y-m-d H: I: s", time () + 8*60*60 );
?>

When the date function outputs a date, it will find that the date is related to the correct date for 8 hours. The sample code is as follows...

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.