Incorrect date obtained by The php date function

Source: Internet
Author: User

Example.

Echo $ showtime = date ("Y-m-d H: I: s ");

10:44:47

The real time is

18:44:47

From the above point of view, the difference is 8 hours. Baidu search found that the default time set for PHP is based on Greenwich Mean Time Zone. We only need to change it to Beijing time.

If you cannot modify php. ini, add date_default_timezone_set (XXX) to the time initialization statement );

Modify php. ini. Then you can set the date. timezone = ??? Change to date. timezone = PRC

Then test

<? Php
Date_default_timezone_set ('prc'); // Set the time zone to Beijing before getting the time using the date function of PHP.
Echo "Current time:". date ('Y-m-d H: I: s'); // Obtain the current time
?>

Current time: 18:44:47

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.