PHP’s date.timezone setting and date_default_timezone_set function

In newer versions of PHP, you are required to set the system’s timezone. If you’ve encountered either of the errors below, or something like them, you need to do this.

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

To do it server-wide, simply edit your php.ini file. If you are not sure where it is, use locate -i php.ini to find it.

Uncomment the following line and set it to your desired timezone:

;date.timezone =

I am on the West Coast of Canada, so I set mine to Vancouver:

date.timezone = America/Vancouver

You will need to restart your web server after making changes to the php.ini file.

If you want to set it on a single file, or override the global settings, you can use the date_default_timezone_set() function:

<?php

date_default_timezone_set('America/Vancouver');

?>

If you are using FreeBSD, here’s a list of timezones:

Setting your timezone in FreeBSD

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.