Source Code:
(back to article)
<?php $utc_date = '2022-03-03 12:00:00'; $utc_time = new DateTime($utc_date, new DateTimeZone('UTC')); $local_time_zone = new DateTimeZone('America/New_York'); $local_time = new DateTime($utc_date, $local_time_zone); $offset = date_offset_get($local_time); $offset_formatted = gmdate('H:i', abs($offset)); $offset_hours = floor(abs($offset) / 3600); $offset_minutes = (abs($offset) % 3600) / 60; if ($offset < 0) { $sign = '-'; } else { $sign = '+'; } $local_time->modify($sign . $offset_hours . ' hours ' . $sign . $offset_minutes . ' minutes'); echo $local_time->format('Y-m-d H:i:s');
Result:
Report an issue