Affected page
https://www.php.net/manual/en/datetimeimmutable.createfromtimestamp.php
Current issue
It is not documented that createFromTimestamp() sets the timezone to UTC. Which is unexpected, because the absence of a timezone normally uses date_default_timezone_get().
Suggested improvement
-
Document the unexpected UTC timezone.
-
Document the (very ugly) workaround
DateTimeImmutable::createFromTimestamp($someTimestamp)->setTimezone(new DateTimeZone(date_default_timezone_get()));
Additional context (optional)
I created a test at https://3v4l.org/d3Rq1#v8.5.7 which demonstrates the current behaviour.
<?php
if (!date_default_timezone_set('Europe/Amsterdam')) {
throw new Exception('Timezone Europe/Amsterdam does not exist?');
}
echo 'Default timezone: '.date_default_timezone_get().PHP_EOL;
var_dump(new DateTimeZone(date_default_timezone_get()));
$someTimestamp = strtotime('2026-07-03 14:22:17');
echo '--- date'.PHP_EOL;
echo date('Y-m-d H:i:s', $someTimestamp).PHP_EOL;
echo '--- DateTimeImmutable::createFromTimestamp() defaults to UTC timezone'.PHP_EOL;
$dt = DateTimeImmutable::createFromTimestamp($someTimestamp);
echo $dt->format('Y-m-d H:i:s').PHP_EOL;
var_dump($dt->getTimezone());
echo '--- DateTimeImmutable::createFromTimestamp() workaround for current timezone'.PHP_EOL;
$dt = DateTimeImmutable::createFromTimestamp($someTimestamp)->setTimezone(new DateTimeZone(date_default_timezone_get()));
echo $dt->format('Y-m-d H:i:s').PHP_EOL;
var_dump($dt->getTimezone());
outputs:
Default timezone: Europe/Amsterdam
object(DateTimeZone)#1 (2) {
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
--- date
2026-07-03 14:22:17
--- DateTimeImmutable::createFromTimestamp() defaults to UTC timezone
2026-07-03 12:22:17 !!!!!!!! NOTICE THE 2 HOURS DIFFERENCE !!!!!!!!
object(DateTimeZone)#2 (2) {
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
--- DateTimeImmutable::createFromTimestamp() workaround for current timezone
2026-07-03 14:22:17
object(DateTimeZone)#1 (2) {
["timezone_type"]=>
int(3)
["timezone"]=>
string(16) "Europe/Amsterdam"
}
Affected page
https://www.php.net/manual/en/datetimeimmutable.createfromtimestamp.php
Current issue
It is not documented that
createFromTimestamp()sets the timezone to UTC. Which is unexpected, because the absence of a timezone normally usesdate_default_timezone_get().Suggested improvement
Document the unexpected UTC timezone.
Document the (very ugly) workaround
Additional context (optional)
I created a test at https://3v4l.org/d3Rq1#v8.5.7 which demonstrates the current behaviour.
outputs: