Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save serverdensity/82576 to your computer and use it in GitHub Desktop.
Save serverdensity/82576 to your computer and use it in GitHub Desktop.
Generate a list of timezones with PHP
http://www.php.net/manual/en/function.timezone-identifiers-list.php
<?php
$zones = timezone_identifiers_list();
foreach ($zones as $zone)
{
$zoneExploded = explode('/', $zone); // 0 => Continent, 1 => City
// Only use "friendly" continent names
if ($zoneExploded[0] == 'Africa' || $zoneExploded[0] == 'America' || $zoneExploded[0] == 'Antarctica' || $zoneExploded[0] == 'Arctic' || $zoneExploded[0] == 'Asia' || $zoneExploded[0] == 'Atlantic' || $zoneExploded[0] == 'Australia' || $zoneExploded[0] == 'Europe' || $zoneExploded[0] == 'Indian' || $zoneExploded[0] == 'Pacific')
{
if (isset($zoneExploded[1]) != '')
{
$area = str_replace('_', ' ', $zoneExploded[1]);
if (!empty($zoneExploded[2]))
{
$area = $area . ' (' . str_replace('_', ' ', $zoneExploded[2]) . ')';
}
$locations[$zoneExploded[0]][$zone] = $area; // Creates array(DateTimeZone => 'Friendly name')
}
}
}
?>
The $locations array will contain a multi-dimensional array for each continent like
Array
(
[Africa] => Array
(
[Africa/Abidjan] => Abidjan
[Africa/Accra] => Accra
[Africa/Addis_Ababa] => Addis Ababa
[Africa/Algiers] => Algiers
...
)
[America] => Array
(
[America/Adak] => Adak
[America/Anchorage] => Anchorage
[America/Anguilla] => Anguilla
...
@arturmamedov
Copy link

Thanks work for me, i just do some changes for work in Smarty :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment