PHP warning: Date () [function. Date]: it is not safe to rely on the system's timezone

Source: Internet
Author: User
Tags echo date what php

When PHP versions later than php5.3 are used, if it is time-related,

"Php warning: Date () [function. DATE]: it is not safe to rely on the system's timezone settings. you are * required * to use the date. timezone setting or the date_default_timezone_set () function. in case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. we selected 'utc' for '8. 0/No DST 'Instead in"

This is an error. How can this problem be solved?

 

In fact, when using functions such as date () in PHP 5.1.0, if the timezone settings are incorrect, the e_notice or e_warning information will be generated each time the time function is called. In php5.1.0, date. the timezone option is disabled by default. No matter what php Command is used, the Greenwich Mean Time is used. However, it seems that this error will be forcibly thrown out in php5.3 if it is not set, to solve this problem, just localize it.

There are three methods (either of them ):

1. Use date_default_timezone_set () in the page header to set date_default_timezone_set ('prc'); // echo date ('Y-m-d h: I: s') in the East eight time zone ');

 

2. Use ini_set ('date. timezone ', 'Asia/Shanghai') in the page header ');

 

3. Modify PHP. ini. Open php5.ini to search for date. timezone. Remove the semicolon and change it to: Date. timezone = PRC.

Restart the HTTP service (such as apache2 or IIS.

Xxx can be any correct value. In China, the following values can be used: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (Chongqing, Shanghai, and Urumqi in sequence). Hong Kong and Taiwan regions are available: Asia/Macao, asia/hong_kong, Asia/Taipei (Macau, Hong Kong, and Taipei in sequence), Singapore: Asia/Singapore, and PRC.

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.