Solve the "It is isn't safe to rely on the" system ' s timezone settings "problem _php skills in PHP

Source: Internet
Author: User
Tags configuration php php programming what php

If you use the PHP5.3 version above, the PHP date function error will occur if you do not have the correct configuration php.ini. A lot of old PHP programming tutorials did not mention this problem, so many readers will feel puzzled, the following author for you to solve this problem three ways.
"PHP Warning:
Date () [Function.date]: It is 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 ' UTC ' for ' 8.0/no DST ' instead in '

In fact, from PHP 5.1.0, when a function such as the date () is used, a e_notice or e_warning information is generated when the timezone is set incorrectly and every time function is invoked. And in the PHP 5.1.0, date.timezone This option, by default is closed, no matter what PHP command is Greenwich Standard Time, but PHP 5.3 as if there is no setting will be forced to throw this error, to solve this problem, as long as localized on the line.

First , in the page using Date_default_timezone_set () Set Date_default_timezone_set (' PRC '); East Eight time zone echo
Date (' y-m-d h:i:s ');

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

Third, modify PHP.ini (if it is Windows system, then file in C disk, Windows directory, if the system is installed in C disk). Use Notepad to open php.ini find date.timezone Remove the preceding semicolon modify to become: Date.timezone = PRC
Restart the HTTP service (such as Apache2 or IIS)!

One of the above three methods can be selected, the small series recommend the use of a third method, do not need to add additional code each time.

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.