Date warnings

When I run

echo "<td>".date( 'm/d/y', strtotime($row['r_date']))."</td>";

I get these warnings

Warning: strtotime(): 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 the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in /home/luke69/public_html/reviews.php on line 181

Warning: 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 the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in /home/luke69/public_html/reviews.php on line 181

Do I fix it like (I think this worked)

date_default_timezone_set('America/Los_Angeles');

that is the inline fix (i.e. you put that into the affected script).

to prevent that on a global level, you would have to set the date.timezone setting in your php.ini.

This is just a warning but an important one.
By default, PHP will use your systems time settings, that includes the date and timezone information, among other things.
PHP believes that this isn’t ideal so it wants you to explicitly specify which timezone should be used.

There are two ways to do this.

The first is a global fix, where you set the timezone info in your php.ini file. Open up your php.ini file and look for date.timezone (See date.timezone in the manual) and change the value to a recognized timezone. You can also use ini_set() to do this, btw.
You may have to restart your web server if you make this change in php.ini.

The other option is to use date_default_timezone_set() to, once again, set a recognized timezone.

Once you make one of the above two changes, you should not see that warning anymore.

For my limited need of time functions, none of which accuracy is of any importance, it makes no difference that my site’s server is 3 timezones away.

Though for me the Warnings are more an annoyance than anything I need to be worried about the few places I use time functions, I can see where for some sites having the timezones match the site’s geographical location would be essential.

Because my shared host doesn’t allow me access to the ini file, I added this line to the files where needed and it works fine
date_default_timezone_set("US/Eastern");

A tricky part may be finding the correct string to use, As Koobi posted, they can be found from here
http://php.net/manual/en/timezones.php

Also, if you look at the table for date.timezone, you can see that the Changeable field has value PHP_INI_ALL which, according to the section titled Where a configuration setting may be set, means the value can be set using one of the following:

  • ini_set()
  • php.ini, .htaccess, httpd.conf (apache2.conf) or .user.ini

But since date.timezone() happens to have the date_default_timezone_set() function, that works fine too.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.