3v4l.org

run code in 300+ PHP versions simultaneously
<?php // @see https://stackoverflow.com/questions/77131068/how-to-retain-the-time-zone-info-when-truncating-a-timestamp-with-time-zone date_default_timezone_set('UTC'); $dates = [ '1999-12-31 20:59:59+00', '1999-12-31 20:59:59', '2000-01-01 07:29:59', '1999-12-31 20:00:00+00', '1999-12-31 20:00:00', '2000-01-01 07:00:00', '2000-01-01 07:00:00 +00', '2000-01-01 07:00:00 Australia/Adelaide' ]; foreach ($dates as $dateString) { $date = new \DateTimeImmutable($dateString); echo $dateString."\n-> ".$date->format('r')."\n\n"; }

preferences:
34.37 ms | 404 KiB | 5 Q