Home » Php » PHP timezone not set

PHP timezone not set

Posted by: admin July 12, 2020 Leave a comment


First of all, i don’t have access to the php.ini in the webserver.

In my local server I put date.timezone = "Europe/Lisbon" in my php.ini.

Is it possible to change this in .htaccess? or, what is the alternative?

At the moment I get this error in web server for phpmailer():

Strict Standards:  date(): It is not safe to rely on the system's timezone settings. ....
How to&Answers:

On second thought, ini_set may not be the best way to go. Apparently E_STRICT standards say that you should use date_default_timezone_set instead.

Try something like:


$tz = date_default_timezone_get();

More info can be found here about the issue:

And here for the default_timezone functions:

Edit: I found this little gem while I was browsing github.

// has to be set to reach E_STRICT compatibility, does not affect system/app settings

This seems like the best solution.


Try ini_set at the top of your script.

ini_set("date.timezone", "Europe/Lisbon");


Your problem is not difficult. You can change date.timezone in the php.ini and delete => ; <= is the comment in the php.ini

for example

; Defines the default timezone used by the date functions

; http://php.net/date.timezone

date.timezone =Europe/Paris