Home>

If using php5.3 or higher,If php.ini is not configured correctly, a php date function error will occur.Many old PHP programming tutorials didn't mention this problem before,So many readers will feel confused,Below I will tell you three ways to solve this problem.

"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 "

In fact, from php 5.1.0, when using functions like date (),If timezone is set incorrectly,Every time the time function is called,E_notice or e_warning information will be generated. And in PHP 5.1.0, the date.timezone option,It is off by default,No matter what php command you use is Greenwich Mean Time,But it seems that if php 5.3 is not set, this error will be forcibly thrown.Solve this problem,Just localize it.

One,Use date_default_timezone_set () in the header to set date_default_timezone_set ("prc");//Eastern time zone echo

date ("y-m-d h:i:s");

two,Use ini_set ("date.timezone", "asia/shanghai") in the header;

three,Modify php.ini (If it is a windows system, the file is in the C drive and the windows directory, if the system is installed in the C drive). Use Notepad to open php.ini to find date.timezone. Remove the semicolon and modify it to:date.timezone=prc

Restart the http service (such as apache2 or iis, etc.)!

You can choose any one of the above three methods.We recommend the third method,No need to add extra code every time.

php
  • Previous Multi-level menu effect with horizontal slideout in JavaScript
  • Next Detailed method of setting font and color using Java