default timezone error in php
-
22-07-2019 - |
Question
I got the following error/warning while tring to install Kohana/SilverStripe.
What does it mean and What do I do for it?
Warning:
date_default_timezone_get():
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 'Asia/Calcutta' for '5.5/no DST' instead in C:\Server\apache\htdocs\kohana\system\core\Kohana.php on line 136
Thanks in Advance!
Solution
This is not an error, but a warning, so it does not block your app from working.
Explicitly set the right timezone using date_default_timezone_set() in C:\Server\apache\htdocs\kohana\system\core\Kohana.php on line 136
You have to choose among valid timezones
Edit
As the warning message itself states you actually have a more clean choice then editing a third party software file. I.e. configuring PHP as it should be.
- edit your
php.ini
and adjust the value ofdate.timezone = America/New_York
or
- use a
php_value
directive in your web server config to set it in your vhost configuration or.htaccess
:php_value date.timezone America/New_York
OTHER TIPS
The OP's comment to his own question above implies that the default timezone cannot be set in php.ini, which is not true — in fact, in many cases setting it there is preferred. And since this SO answer is one of the first hits in Google for "php default timezone error", I'll save others some lost sanity.
A very common cause of this error is not so much to misspell the zone city or country (e.g. "New York", "Los Angeles") in the php.ini file being used, but instead, to include embedded spaces rather than underscores in the identifier, and thus "misspell" the full constant.
This will also do what you want, without having to set it on every page at runtime (verified on PHP 5.4 and 5.3, in Windows, Linux and OSX):
In php.ini:
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = America/New_York
; ^^^^^^^^^^^^^^^^ * Must_Use_Underscores *
Also, if you've checked and re-checked the spelling and are certain it's right, make sure you're editing the actual php.ini file that's being used:
Web context (create a test file test.php, and then confirm the date.timezone
there):
<?php phpinfo(); ?>
Command line Linux/OSX:
$ php -i | grep "timezone"
Command line Windows:
C:\> php -i | find "timezone"
The precedence order for retrieving the default date timezone configuration is spelled out in detail here.
If you don't have the ability to change php.ini
, add this to your _ss_environment.php
or mysite/_config.php
files:
date_default_timezone_set('...');
where ...
is one of the valid PHP timezones.