Date function in PHP date (): It isn't safe to rely

Source: Internet
Author: User
Tags php code


When you call the date function in your PHP code, you see the following error in the log

PHP warning:date (): It isn't safe to rely on the system's timezone settings.
You are are *required* to use the Date.timezone setting or the Date_default_timezone_set () function.
In case you are used any of those methods and your are still getting this warning,
You most likely misspelled the timezone identifier. We selected ' asia/chongqing ' for ' cst/8.0/no DST ' instead

Why is there such an error?

The time zone setting (Date.timezone) is referenced from PHP 5.1.0, but it is closed by default, so using functions such as date () produces e_notice or e_warning information.

Treatment Method 1

Add code before calling date


Add code to the header: Ate_default_timezone_set ("PRC");
Add code to the header: Ini_set (' Date.timezone ', ' Comment: RPC ');
Enable the Date.timezone setting in php.ini and set its value: DATE.TIMEZONE=PRC, and restart Apache;

Note: RPC represents the People's Republic of China.

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.