Skip to content

Instantly share code, notes, and snippets.

@stevebauman
Created May 19, 2022 13:56
Show Gist options
  • Save stevebauman/122ed0899e4c988bec5c84178c23bd69 to your computer and use it in GitHub Desktop.
Save stevebauman/122ed0899e4c988bec5c84178c23bd69 to your computer and use it in GitHub Desktop.
Human Friendly Timezone List Generator PHP
$timezones = array_map(function ($timezone) {
$date = new DateTime('now', $tz = new DateTimeZone($timezone));
return [
'timezone' => $timezone,
// Format: "(GMT -05:00) America/Toronto"
'label' => "({$date->format('\G\M\T P')}) {$tz->getName()}",
];
}, DateTimeZone::listIdentifiers());
@stevebauman
Copy link
Author

Generates associative array:

[
    "timezone" => "Africa/Abidjan",
    "label" => "(GMT +00:00) Africa/Abidjan",
],
[
    "timezone" => "Africa/Accra",
    "label" => "(GMT +00:00) Africa/Accra",
],
// ...

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