-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Description
The following code:
<?php
// given: a time string including timezone (Zulu)
$zuluTimeString = '2024-11-07T11:00:00Z';
$dt = new DateTime($zuluTimeString, new DateTimeZone('Europe/Berlin'));
var_dump($dt->getTimeZone()->getName());
var_dump($dt->format('Y-m-d H:i:sp'));
$dt = new DateTime($zuluTimeString);
$dt->setTimezone(new DateTimeZone('Europe/Berlin'));
var_dump($dt->getTimeZone()->getName());
var_dump($dt->format('Y-m-d H:i:sp'));
$dt = new DateTimeImmutable($zuluTimeString, new DateTimeZone('Europe/Berlin'));
var_dump($dt->getTimeZone()->getName());
var_dump($dt->format('Y-m-d H:i:sp'));
$dt = new DateTimeImmutable($zuluTimeString);
$dt->setTimezone(new DateTimeZone('Europe/Berlin'));
var_dump($dt->getTimeZone()->getName());
var_dump($dt->format('Y-m-d H:i:sp'));
?>
Resulted in this output:
string(1) "Z"
string(20) "2024-11-07 11:00:00Z"
string(13) "Europe/Berlin"
string(25) "2024-11-07 12:00:00+01:00"
string(1) "Z"
string(20) "2024-11-07 11:00:00Z"
string(1) "Z"
string(20) "2024-11-07 11:00:00Z"
But I expected this output instead:
either (always)
string(13) "Europe/Berlin"
string(25) "2024-11-07 12:00:00+01:00"
or Error / Warning due to Timezone conflict in parameters
PHP Version
PHP 8.3.10
Operating System
MacOS 12.7.4