PHP warning:date () [function.date]: It is not safe for rely on the system ' s timezone

Source: Internet
Author: User
Tags echo date

When using PHP version above PHP5.3, as long as the time involved will be reported a

PHP warning:date () [function.date]: It is not safe to rely on the system ' s timezone settings. You is *required* to use the Date.timezone setting or the Date_default_timezone_set () function. In case you used any of those methods and you is still getting this warning, your most likely misspelled the timezone Iden Tifier. We selected ' UTC ' for ' 8.0/no DST ' instead in '

Such a mistake. How to fix it?

In fact, from PHP 5.1.0, when a function such as date () is used, if timezone is set incorrectly, E_notice or e_warning information is generated every time the function is called. And in php5.1.0, date.timezone this option, by default, is off, no matter what the PHP command is Greenwich Mean time, but the PHP5.3 seems to be forced to throw the error if there is no setting, to solve this problem, as long as the localization, it is OK.

Here are three ways to do it (any one of them):

First, use Date_default_timezone_set () to set Date_default_timezone_set (' PRC ') on the page header; East Eight time zone echo date (' y-m-d h:i:s ');

Second, use Ini_set (' Date.timezone ', ' Asia/shanghai ') in the head of the page;

Third, modify the php.ini. Open Php5.ini Find Date.timezone Remove the previous semicolon modification to become: Date.timezone =PRC

Restart the HTTP service (such as Apache2 or IIS).

XXX can be any correct value. For our country: can be the following values: Asia/chongqing, Asia/shanghai, Asia/urumqi (Chongqing, Shanghai, Urumqi, respectively) Taiwan available: Asia/macao, Asia/hong_kong, asia/ Taipei (Macao, Hong Kong, Taipei) and Singapore: Asia/singapore, and of course PRC.

PHP warning:date () [function.date]: It is not safe for rely on the system ' s timezone

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.