Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP timezone not set

Tags:

timezone

php

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. ....
like image 453
user455318 Avatar asked Jun 01 '11 22:06

user455318


People also ask

How do I change the default timezone in PHP?

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

What is PHP default timezone?

The default timezone for PHP is UTC regardless of your server's timezone. This is the timezone used by all PHP date/time functions in your scripts.

How can I get timezone in PHP?

The date_default_timezone_get() function returns the default timezone used by all date/time functions in the script.


2 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:

date_default_timezone_set('Europe/Lisbon');

$tz = date_default_timezone_get();

More info can be found here about the issue: http://answers.google.com/answers/threadview/id/739376.html

And here for the default_timezone functions:
http://us2.php.net/manual/en/function.date-default-timezone-set.php

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
date_default_timezone_set(date_default_timezone_get());

This seems like the best solution.

like image 196
Swift Avatar answered Nov 09 '22 03:11

Swift


Try ini_set at the top of your script.

ini_set("date.timezone", "Europe/Lisbon");
like image 39
icktoofay Avatar answered Nov 09 '22 04:11

icktoofay