PHP uses the date () function to prompt for warning:date () errors

Source: Internet
Author: User
Tags what php

In the PHP version above PHP5.3, as long as the time is involved will report a
"PHP warning:date () [function.date]: It is isn't safe to rely on the system ' 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, for you most likely
Misspelled the timezone identifier. We selected ' UTC ' for ' 8.0/no DST ' instead in '
Such a mistake. How to solve it?

In fact, from PHP 5.1.0, when you use a function such as date (), if the timezone is set incorrectly, every time function is called, it will
Generate E_notice or e_warning information. And again in php5.1.0, date.timezone this option, which is off by default, without
What PHP command is used is Greenwich Mean time, but PHP5.3 seems to be forced to throw the error if there is no setting, to resolve the question
Problem, as long as the localization, on the line.
Here are three methods (any of which can be selected):
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 the php.ini. Open Php5.ini Find Date.timezone Remove the preceding semicolon modify to become: Date.timezone =PRC
Restart the HTTP service (such as Apache2 or IIS, etc.).
XXX can be any correct value. For our domestic: can be the following values: Asia/chongqing, Asia/shanghai, Asia/urumqi
(in turn, Chongqing, Shanghai, Urumqi) Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macao in turn)
, Hong Kong, Taipei, and Singapore: Asia/singapore, of course, PRC is OK.

Summary, the original before the php5.3 version of the date is not strictly limited so it is my date set is not correct and no problem, but after php5.3.

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.