Created
April 10, 2011 21:45
-
-
Save hamishcampbell/912757 to your computer and use it in GitHub Desktop.
Quick PHP timezone juggling example.
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 | |
$timezoneAuckland = new DateTimeZone('Pacific/Auckland'); | |
$timezoneHelsinki = new DateTimeZone('Europe/Helsinki'); | |
$currentTime = new DateTime('now', $timezoneAuckland); | |
$helsinkiTime = new DateTime('now', $timezoneHelsinki); | |
printf( | |
"It is currently %s <br>", | |
$currentTime->format(DateTime::RSS) | |
); | |
printf( | |
"In Helsinki it is %s<br>", | |
$helsinkiTime->format(DateTime::RSS) | |
); | |
printf( | |
"The time difference is %d hours.<br>", | |
($currentTime->getOffset() + $helsinkiTime->getOffset()) / 60 / 60 | |
); | |
echo "All available timezones:<br><ul>"; | |
foreach(DateTimeZone::listIdentifiers() as $timezone) | |
printf("<li>%s</li>", $timezone); | |
echo "<ul>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment