Created
April 5, 2012 16:48
-
-
Save wilmoore/2312469 to your computer and use it in GitHub Desktop.
Playing with DateTime and DateTimeZone
This file contains hidden or 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 | |
// assume these preferences came from a database as-is | |
$userTimezonePreference = 'America/Denver'; | |
$userStoredDateTime = '2012-04-02 00:15:40'; | |
$dateTime = new DateTime($userStoredDateTime, new DateTimeZone($userTimezonePreference)); | |
echo 'ORIG: ', $dateTime->format(DateTime::RFC2822), PHP_EOL; | |
$dateTime->setTimezone(new DateTimeZone('UTC')); | |
echo 'USER: ', $dateTime->format(DateTime::RFC2822), PHP_EOL; |
This file contains hidden or 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 | |
// assume these preferences came from a database as-is | |
$userTimezonePreference = 'America/Denver'; | |
$storedDateTimeAsUtc = '2012-04-02 06:15:40'; | |
$dateTime = new DateTime($storedDateTimeAsUtc, new DateTimeZone('UTC')); | |
echo 'ORIG: ', $dateTime->format(DateTime::RFC2822), PHP_EOL; | |
$dateTime->setTimezone(new DateTimeZone($userTimezonePreference)); | |
echo 'USER: ', $dateTime->format(DateTime::RFC2822), PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment