Skip to content

Instantly share code, notes, and snippets.

@hamishcampbell
Created April 10, 2011 21:45
Show Gist options
  • Save hamishcampbell/912757 to your computer and use it in GitHub Desktop.
Save hamishcampbell/912757 to your computer and use it in GitHub Desktop.
Quick PHP timezone juggling example.
<?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