Last active
January 29, 2019 21:07
-
-
Save jrodriguez-ifuelinteractive/f715418cb1e26fd15dd396b902405991 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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