0

This script:

<?php
    $dateTime = new DateTime();
?>

Throws this error:

PHP Fatal error:  Uncaught Exception: DateTime::__construct(): Invalid date.timezone value 'America/Argentia/Buenos_Aires', we selected the timezone 'UTC' for now. in /var/www/html/date.php:2
Stack trace:
#0 /var/www/html/date.php(2): DateTime->__construct()
#1 {main}
  thrown in /var/www/html/date.php on line 2

Pay attention to the timezone "Argentia", looks like a typo, but I do not know WHERE it's configured.

What I already try:

  • I edited the timezone in php.in: date.timezone = "America/Argentina/Buenos_Aires" and restart apache2 service.
  • I checked the server timezone (that's ok):
# timedatectl | grep "Time zone"
Time zone: America/Argentina/Buenos_Aires (-03, -0300)

Note: Adding the following line at the start of the script date_default_timezone_set("America/Argentina/Buenos_Aires"); The problem "is solved", but I am looking for a general solution to the problem.

System info: Ubuntu 16.04 and PHP 7.4

Thanks!

  • The default timezone is configured by the `data.timezone` entry in PHP.INI. You say you've edited that, so that is your general solution. If that didn't fix the problem are you sure you've edited the right copy of PHP.INI? – Tangentially Perpendicular Jan 21 '21 at 21:48
  • 1
    Does this answer your question? [Setting the Timezone for PHP in the php.ini file](https://stackoverflow.com/questions/32224547/setting-the-timezone-for-php-in-the-php-ini-file) – Tangentially Perpendicular Jan 21 '21 at 21:49
  • **phpinfo() shows me:** Loaded Configuration File /etc/php/7.4/apache2/php.ini date.timezone America/Argentia/Buenos_Aires America/Argentia/Buenos_Aires **And when edit this file, I have:** date.timezone = "America/Argentina/Buenos_Aires" I'm restarting Apache using: sudo service apache2 restart I don't know what's wrong! – Fabricio Bianchi Jan 21 '21 at 22:39

1 Answers1

1

I tried the solutions posted, but they didn't work for me. I wrote a phpinfo() page to shows me the location of the php.ini file. Then, I edited it to set a new date.timezone, and restarted the server, the change hasn't impact.

This is what helped me to fix the wrong timezone:

  1. I find the typo wrong timezone under the php folder, using:
grep -rl "Argentia" /etc/php
  1. Command's output:
/etc/php/7.4/mods-available/Custom.ini
  1. So, I edit the finded file and modify the timezone.
  2. Restart the apache2 services, and it works!