3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tz = 'Australia/Sydney'; $date_start = new \DateTime('2010-03-01', new \DateTimeZone($tz)); //(+11 UTC) $date_end = new \DateTime('2010-07-29', new \DateTimeZone($tz)); //(+10 UTC) $interval = $date_start->diff($date_end); $utc_start = $date_start->format('U'); $utc_end = $date_end->format('U'); $start = new \DateTime('@' . $utc_start); $start_5_month = new \DateTime($start->format('Y-m-d H:i:s') . ' +5 month', new DateTimeZone($tz)); //5 Month "UTC" without AEST change var_dump('Start: ' . ((new \DateTime('@' . $utc_start))->format('Y-m-d H:i:s')), 'End: with AEST change ' . ((new \DateTime('@' . $utc_end))->format('Y-m-d H:i:s')), $start_5_month, $interval); echo '5 month 2010-07-28 12:00:00.000000 timezone Australia/Sydney/+10 UTC correct';

preferences:
24.77 ms | 404 KiB | 5 Q