php / php/doc-en

DateTimeImmutable::createFromTimestamp() uses UTC timezone

Open Beginner friendly
#5,651 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

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
  1. Document the unexpected UTC timezone.

  2. 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"
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the affected DateTimeImmutable::createFromTimestamp() manual page and inspect its existing description and examples. Document that the method uses UTC and include the proposed workaround for the default timezone, then verify that the page clearly reflects the demonstrated behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.