PHP DateTime issues a timezone warning even if date.timezone is set

I constantly get the following error:

DateTime :: createFromFormat (): You cannot rely on the system time zone settings. You must use the date.timezone parameter or the date_default_timezone_set () function. If you used any of these methods and you still get this warning, most likely you are mistaken with the time zone identifier. At the moment, we have selected the time zone "UTC", but please set date.timezone to select the time zone. in

Although I set the DateTime parameters in my php.ini as follows:

date.timezone = Asia/Jakarta 

Any idea?

+6
source share
6 answers

You just do not have enough quotation marks.

 date.timezone = "Asia/Jakarta" 

Good luck

It may also be that you are not loading the correct php.ini file. See this post for more information: php5.3.3 date.timezone again the php.ini directive is not taken into account

+4
source

you can use

 date_default_timezone_set("Asia/Jakarta") 

at the beginning of your script

+3
source

Perhaps this process runs in php cli, so you need to put this configuration in your php.ini CLI along the following path: /etc/php5/cli/php.ini

By default, "date.timezone" is commented out, so change this configuration: date.timezone = Asia / Jakarta

0
source

For those who have the same problem in Symfony 3, add the following constructor to the app / appKernel.php file and restart nginx.

 public function __construct($environment, $debug) { date_default_timezone_set('Asia/Jakarta'); parent::__construct($environment, $debug); } 
0
source

I also specified DateTime parameters in my php.ini. In my case, the editable php.ini was on

 /Applications/MAMP/bin/php/php7.1.1/conf/php.ini 

since I saw the path from info.php (in the "Loaded configuration file") that I generated on localhost.

It turns out that this is not the one that is used. Try instead:

 php -i | grep php.ini 

And let's see what a way out is. My was:

 /usr/local/etc/php/5.6 Loaded Configuration File => /usr/local/etc/php/5.6/php.ini PHP Warning: Unknown: It is not safe to rely on the system 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. in Unknown on line 0 

And then I just go to "/usr/local/etc/php/5.6" and edit the date.timezone line: delete the comment (;) and add "Europe / Berlin" (or, in your case, "Asia / Jakarta" ".)

Try "php -i | grep php.ini" again and the php warning message should disappear.

 php -i | grep php.ini Configuration File (php.ini) Path => /usr/local/etc/php/5.6 Loaded Configuration File => /usr/local/etc/php/5.6/php.ini 
0
source

Without working with the above solutions, try adding the following code to the .htaccess of your root directory and check.

 php_value date.timezone America/Denver 
0
source

Source: https://habr.com/ru/post/958354/


All Articles