3v4l.org

run code in 300+ PHP versions simultaneously
<?php class User{ public function getDateTime($time = 'now'){ $dt = new DateTime($time); $dt->setTimezone(new DateTimeZone("Europe/Warsaw"));//in reality you get that from user settings return $dt; } } $user = new User(); $dt = $user->getDateTime(); echo $dt->format("Y-m-d H:i:s e") . "\n"; //before inserting to DB: $dt->setTimezone(new DateTimeZone("UTC")); echo $dt->format("Y-m-d H:i:s e") . "\n";
Output for 7.1.20, 7.2.6 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.27, 8.2.0 - 8.2.17, 8.3.0 - 8.3.4
2017-10-22 22:47:52 Europe/Warsaw 2017-10-22 20:47:52 UTC
Output for 7.0.0 - 7.0.24, 7.1.0 - 7.1.10
2017-10-22 22:46:08 Europe/Warsaw 2017-10-22 20:46:08 UTC

preferences:
161.96 ms | 401 KiB | 175 Q