user1322720
user1322720

Reputation:

Do I need to set the timezone in a PHP script, if it is set in php.ini?

phpinfo() tells me that my timezone is properly set:

enter image description here

date_default_timezone_get() returns "Europe/Berlin". Since I'm on 5.4.35 this should return the ini option (see the manual).

Do I still need to set the timezone, as PHP's warning tells me?

Strict Standards: 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 'Europe/Berlin' for 'CET/1.0/no DST' instead in /your/skript.php on line 249

Upvotes: 0

Views: 1566

Answers (1)

Carey
Carey

Reputation: 670

Yes, you should always set the timezone, even if it is set on the server. This is needed as your script may not always run on that server, and may throw errors if moved to a server with an unset timezone.

Generally a good option for timezones is UTC:

date_default_timezone_set('UTC')

Upvotes: 2

Related Questions