PHP Gets the current 8-hour time lag problem

Source: Internet
Author: User
Tags current time echo date ini what php

<?php

echo Date ("y-m-d h:i:s"); Current time
?>

This method obtains time and standard difference of 8 hours;

Starting with php5.1.0, PHP.ini added the Date.timezone option, which is closed by default

That is, the time that is displayed (no matter what PHP command is used) is Greenwich Standard Time

And our Time (Beijing time) is bad for just 8 hours, there are the following 3 methods can restore normal time.

1, the easiest way is not to use the php5.1 version

2, if you must use, and can not modify the php.ini, you need in the initialization of the statement of the time
Add Date_default_timezone_set (XXX) above;
CP does not have this problem

3, once and for all, only can modify php.ini. Open php.ini Find Date.timezone remove the preceding semicolon
= Add xxx back, restart HTTP service (such as Apache2 or IIS, etc.)

For XXX, the values available in mainland China are: Asia/shanghai

Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei)
and Singapore: Asia/singapore

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.