Last active
August 29, 2015 14:20
-
-
Save hirejordansmith/a12a86466fe8d40b9943 to your computer and use it in GitHub Desktop.
Change the default timezone being used for PHP DateTime Class
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 | |
// This will output current time in EST | |
$timezone = 'EST'; | |
$timestamp = time(); | |
$datetime = new DateTime("now", new DateTimeZone($timezone)); //first argument "must" be a string | |
$datetime->setTimestamp($timestamp); //adjust the object to correct timestamp | |
echo '<b>Current Time: </b>' . $datetime->format('Ymd ga e'); | |
echo '<br />'; | |
// This will output current time + 24 hours in EST | |
$timezone = 'EST'; | |
$timestamp = time()+86400; | |
$datetime = new DateTime("now", new DateTimeZone($timezone)); //first argument "must" be a string | |
$datetime->setTimestamp($timestamp); //adjust the object to correct timestamp | |
echo '<b>+24 hours:</b> ' . $datetime->format('Ymd ga e'); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment