Skip to content

Instantly share code, notes, and snippets.

@jrodriguez-ifuelinteractive
Last active January 29, 2019 21:07
Show Gist options
  • Save jrodriguez-ifuelinteractive/f715418cb1e26fd15dd396b902405991 to your computer and use it in GitHub Desktop.
Save jrodriguez-ifuelinteractive/f715418cb1e26fd15dd396b902405991 to your computer and use it in GitHub Desktop.
<?php
$dateString = '2019-01-21';
$originTimezone = 'America/New_York';
$date = new DateTime($dateString, new DateTimeZone($originTimezone));
$offset = $date->getOffset();
$utc = new DateTime($dateString, new DateTimeZone('UTC'));
$interval = new DateInterval(sprintf('PT%sS', abs($offset)));
if ($offset <= 0) {
$utc->add($interval);
} else {
$utc->sub($interval);
}
echo "$originTimezone: " . $date->format('Y-m-d H:i:s e') . "\n";
echo 'UTC: ' . $utc->format('Y-m-d H:i:s e') . "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment