<?php
foreach (['Etc/GMT+12', 'Etc/GMT-10'] as $timezone) {
$dTZ = new DateTimeZone($timezone);
// Create a DateTime using the DateTimeZone object
// This will display both formatted and unix timestamp as expected
$dT = new DateTime('2013-12-13 18:49:00', $dTZ);
echo $dT->format('Y-m-d H:i:s T'), PHP_EOL;
echo $dT->getTimestamp(), PHP_EOL;
// Create a DateTime using only a string representation
// This will display the formatted date/time as expected,
// but with the incorrect timezone
// The value returned by getTimestamp() for format('U') will
// be off by 2*offset
$dT2 = new DateTime($dT->format('Y-m-d H:i:s T'));
echo $dT2->format('Y-m-d H:i:s T'), PHP_EOL;
echo $dT2->getTimestamp(), PHP_EOL, PHP_EOL;
}
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
2013-12-13 18:49:00 -12
1387003740
2013-12-13 18:49:00 GMT-1200
1387003740
2013-12-13 18:49:00 +10
1386924540
2013-12-13 18:49:00 GMT+1000
1386924540
Output for 8.1.14, 8.2.1
Fatal error: Uncaught Exception: DateTimeZone::__construct(): Unknown or bad timezone (Etc/GMT+12) in /in/RCA06:4
Stack trace:
#0 /in/RCA06(4): DateTimeZone->__construct('Etc/GMT+12')
#1 {main}
thrown in /in/RCA06 on line 4
Process exited with code 255.