[php-src] Issue #18870: PHP new DateTime() with unix timestamp ignores Timezone for application and also explicit Timezone in constructor

From: Date: Tue, 17 Jun 2025 13:00:05 +0000
Subject: [php-src] Issue #18870: PHP new DateTime() with unix timestamp ignores Timezone for application and also explicit Timezone in constructor
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-250271@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/18870 Author: camohub ### Description I have an object which have created property like unix timestamp integer. I try to convert this property to DateTime object and supposed the PHP will set up correct Timezone according application settings. Application is Laravel 12 which setting for timezone is correct as I see in a log file. Look at the code: ``` Log::info((new DateTimeZone(config('app.timezone')))->getName()); // Europe/Bratislava $row->created = (new DateTime('@' . $row->created), new DateTimeZone(config('app.timezone'))); Log::info($row->created->getTimezone()->getName()); // +00:00 !!!!! ``` The DateTime constructor completelly ignores second argument. Next code works fine: ``` Log::info((new DateTimeZone(config('app.timezone')))->getName()); // Europe/Bratislava $row->created = (new DateTime('@' . $row->created))->setTimezone(new DateTimeZone(config('app.timezone'))); Log::info($row->created->getTimezone()->getName()); // Europe/Bratislava ``` ### PHP Version ```plain PHP 8.2 ``` ### Operating System Windows 10

« previous php.bugs (#250271) next »