51

I am looking for a way to generate a list of timezones for display in a <select> Generating a drop down list of timezones with PHP

    $list = DateTimeZone::listAbbreviations();
    $idents = DateTimeZone::listIdentifiers();

    $data = $offset = $added = array();
    foreach ($list as $abbr => $info) {
        foreach ($info as $zone) {
            if ( ! empty($zone['timezone_id'])
                AND
                ! in_array($zone['timezone_id'], $added)
                AND 
                  in_array($zone['timezone_id'], $idents)) {
                $z = new DateTimeZone($zone['timezone_id']);
                $c = new DateTime(null, $z);
                $zone['time'] = $c->format('H:i a');
                $data[] = $zone;
                $offset[] = $z->getOffset($c);
                $added[] = $zone['timezone_id'];
            }
        }
    }

    array_multisort($offset, SORT_ASC, $data);
    $options = array();
    foreach ($data as $key => $row) {
        $options[$row['timezone_id']] = $row['time'] . ' - '
                                        . formatOffset($row['offset']) 
                                        . ' ' . $row['timezone_id'];
    }

    // now you can use $options;

function formatOffset($offset) {
        $hours = $offset / 3600;
        $remainder = $offset % 3600;
        $sign = $hours > 0 ? '+' : '-';
        $hour = (int) abs($hours);
        $minutes = (int) abs($remainder / 60);

        if ($hour == 0 AND $minutes == 0) {
            $sign = ' ';
        }
        return 'GMT' . $sign . str_pad($hour, 2, '0', STR_PAD_LEFT) 
                .':'. str_pad($minutes,2, '0');

}

When I checked my country, the offset was wrong, I am in Asia/Singapore, it should be UTC/GMT +8 http://www.timeanddate.com/worldclock/city.html?n=236 but according to the generated list its +9. Is there some kind of logic error? The time was correct tho

Is there a better way to generate this list? from the same question in the link above,

static $regions = array(
    'Africa' => DateTimeZone::AFRICA,
    'America' => DateTimeZone::AMERICA,
    'Antarctica' => DateTimeZone::ANTARCTICA,
    'Aisa' => DateTimeZone::ASIA,
    'Atlantic' => DateTimeZone::ATLANTIC,
    'Europe' => DateTimeZone::EUROPE,
    'Indian' => DateTimeZone::INDIAN,
    'Pacific' => DateTimeZone::PACIFIC
);
foreach ($regions as $name => $mask) {
    $tzlist[] = DateTimeZone::listIdentifiers($mask);
}

This just gets the identifiers I want a friendly display name eg. UTC+8 Asia/Singapore or something similar. How can I get that?

2
  • Note that UTC is not a timezone, but THE time reference upon which timezones and their offsets are based. GMT is the standard timezone for Great Britain, as opposed to BST as its summer time.
    – Patanjali
    Commented Aug 7, 2021 at 22:27
  • Go to the final 2 examples in my answer in stackoverflow.com/a/68690406/4188092 to get a list of timezones using the php intl module.
    – Patanjali
    Commented Aug 13, 2021 at 3:42

14 Answers 14

135

Take my array of time zones, which I made specially for select element. It is associated array where key is PHP time zone and value is human representation. This is it:

$timezones = array(
    'Pacific/Midway'       => "(GMT-11:00) Midway Island",
    'US/Samoa'             => "(GMT-11:00) Samoa",
    'US/Hawaii'            => "(GMT-10:00) Hawaii",
    'US/Alaska'            => "(GMT-09:00) Alaska",
    'US/Pacific'           => "(GMT-08:00) Pacific Time (US &amp; Canada)",
    'America/Tijuana'      => "(GMT-08:00) Tijuana",
    'US/Arizona'           => "(GMT-07:00) Arizona",
    'US/Mountain'          => "(GMT-07:00) Mountain Time (US &amp; Canada)",
    'America/Chihuahua'    => "(GMT-07:00) Chihuahua",
    'America/Mazatlan'     => "(GMT-07:00) Mazatlan",
    'America/Mexico_City'  => "(GMT-06:00) Mexico City",
    'America/Monterrey'    => "(GMT-06:00) Monterrey",
    'Canada/Saskatchewan'  => "(GMT-06:00) Saskatchewan",
    'US/Central'           => "(GMT-06:00) Central Time (US &amp; Canada)",
    'US/Eastern'           => "(GMT-05:00) Eastern Time (US &amp; Canada)",
    'US/East-Indiana'      => "(GMT-05:00) Indiana (East)",
    'America/Bogota'       => "(GMT-05:00) Bogota",
    'America/Lima'         => "(GMT-05:00) Lima",
    'America/Caracas'      => "(GMT-04:30) Caracas",
    'Canada/Atlantic'      => "(GMT-04:00) Atlantic Time (Canada)",
    'America/La_Paz'       => "(GMT-04:00) La Paz",
    'America/Santiago'     => "(GMT-04:00) Santiago",
    'Canada/Newfoundland'  => "(GMT-03:30) Newfoundland",
    'America/Buenos_Aires' => "(GMT-03:00) Buenos Aires",
    'Greenland'            => "(GMT-03:00) Greenland",
    'Atlantic/Stanley'     => "(GMT-02:00) Stanley",
    'Atlantic/Azores'      => "(GMT-01:00) Azores",
    'Atlantic/Cape_Verde'  => "(GMT-01:00) Cape Verde Is.",
    'Africa/Casablanca'    => "(GMT) Casablanca",
    'Europe/Dublin'        => "(GMT) Dublin",
    'Europe/Lisbon'        => "(GMT) Lisbon",
    'Europe/London'        => "(GMT) London",
    'Africa/Monrovia'      => "(GMT) Monrovia",
    'Europe/Amsterdam'     => "(GMT+01:00) Amsterdam",
    'Europe/Belgrade'      => "(GMT+01:00) Belgrade",
    'Europe/Berlin'        => "(GMT+01:00) Berlin",
    'Europe/Bratislava'    => "(GMT+01:00) Bratislava",
    'Europe/Brussels'      => "(GMT+01:00) Brussels",
    'Europe/Budapest'      => "(GMT+01:00) Budapest",
    'Europe/Copenhagen'    => "(GMT+01:00) Copenhagen",
    'Europe/Ljubljana'     => "(GMT+01:00) Ljubljana",
    'Europe/Madrid'        => "(GMT+01:00) Madrid",
    'Europe/Paris'         => "(GMT+01:00) Paris",
    'Europe/Prague'        => "(GMT+01:00) Prague",
    'Europe/Rome'          => "(GMT+01:00) Rome",
    'Europe/Sarajevo'      => "(GMT+01:00) Sarajevo",
    'Europe/Skopje'        => "(GMT+01:00) Skopje",
    'Europe/Stockholm'     => "(GMT+01:00) Stockholm",
    'Europe/Vienna'        => "(GMT+01:00) Vienna",
    'Europe/Warsaw'        => "(GMT+01:00) Warsaw",
    'Europe/Zagreb'        => "(GMT+01:00) Zagreb",
    'Europe/Athens'        => "(GMT+02:00) Athens",
    'Europe/Bucharest'     => "(GMT+02:00) Bucharest",
    'Africa/Cairo'         => "(GMT+02:00) Cairo",
    'Africa/Harare'        => "(GMT+02:00) Harare",
    'Europe/Helsinki'      => "(GMT+02:00) Helsinki",
    'Europe/Istanbul'      => "(GMT+02:00) Istanbul",
    'Asia/Jerusalem'       => "(GMT+02:00) Jerusalem",
    'Europe/Kiev'          => "(GMT+02:00) Kyiv",
    'Europe/Minsk'         => "(GMT+02:00) Minsk",
    'Europe/Riga'          => "(GMT+02:00) Riga",
    'Europe/Sofia'         => "(GMT+02:00) Sofia",
    'Europe/Tallinn'       => "(GMT+02:00) Tallinn",
    'Europe/Vilnius'       => "(GMT+02:00) Vilnius",
    'Asia/Baghdad'         => "(GMT+03:00) Baghdad",
    'Asia/Kuwait'          => "(GMT+03:00) Kuwait",
    'Africa/Nairobi'       => "(GMT+03:00) Nairobi",
    'Asia/Riyadh'          => "(GMT+03:00) Riyadh",
    'Europe/Moscow'        => "(GMT+03:00) Moscow",
    'Asia/Tehran'          => "(GMT+03:30) Tehran",
    'Asia/Baku'            => "(GMT+04:00) Baku",
    'Europe/Volgograd'     => "(GMT+04:00) Volgograd",
    'Asia/Muscat'          => "(GMT+04:00) Muscat",
    'Asia/Tbilisi'         => "(GMT+04:00) Tbilisi",
    'Asia/Yerevan'         => "(GMT+04:00) Yerevan",
    'Asia/Kabul'           => "(GMT+04:30) Kabul",
    'Asia/Karachi'         => "(GMT+05:00) Karachi",
    'Asia/Tashkent'        => "(GMT+05:00) Tashkent",
    'Asia/Kolkata'         => "(GMT+05:30) Kolkata",
    'Asia/Kathmandu'       => "(GMT+05:45) Kathmandu",
    'Asia/Yekaterinburg'   => "(GMT+06:00) Ekaterinburg",
    'Asia/Almaty'          => "(GMT+06:00) Almaty",
    'Asia/Dhaka'           => "(GMT+06:00) Dhaka",
    'Asia/Novosibirsk'     => "(GMT+07:00) Novosibirsk",
    'Asia/Bangkok'         => "(GMT+07:00) Bangkok",
    'Asia/Jakarta'         => "(GMT+07:00) Jakarta",
    'Asia/Krasnoyarsk'     => "(GMT+08:00) Krasnoyarsk",
    'Asia/Chongqing'       => "(GMT+08:00) Chongqing",
    'Asia/Hong_Kong'       => "(GMT+08:00) Hong Kong",
    'Asia/Kuala_Lumpur'    => "(GMT+08:00) Kuala Lumpur",
    'Australia/Perth'      => "(GMT+08:00) Perth",
    'Asia/Singapore'       => "(GMT+08:00) Singapore",
    'Asia/Taipei'          => "(GMT+08:00) Taipei",
    'Asia/Ulaanbaatar'     => "(GMT+08:00) Ulaan Bataar",
    'Asia/Urumqi'          => "(GMT+08:00) Urumqi",
    'Asia/Irkutsk'         => "(GMT+09:00) Irkutsk",
    'Asia/Seoul'           => "(GMT+09:00) Seoul",
    'Asia/Tokyo'           => "(GMT+09:00) Tokyo",
    'Australia/Adelaide'   => "(GMT+09:30) Adelaide",
    'Australia/Darwin'     => "(GMT+09:30) Darwin",
    'Asia/Yakutsk'         => "(GMT+10:00) Yakutsk",
    'Australia/Brisbane'   => "(GMT+10:00) Brisbane",
    'Australia/Canberra'   => "(GMT+10:00) Canberra",
    'Pacific/Guam'         => "(GMT+10:00) Guam",
    'Australia/Hobart'     => "(GMT+10:00) Hobart",
    'Australia/Melbourne'  => "(GMT+10:00) Melbourne",
    'Pacific/Port_Moresby' => "(GMT+10:00) Port Moresby",
    'Australia/Sydney'     => "(GMT+10:00) Sydney",
    'Asia/Vladivostok'     => "(GMT+11:00) Vladivostok",
    'Asia/Magadan'         => "(GMT+12:00) Magadan",
    'Pacific/Auckland'     => "(GMT+12:00) Auckland",
    'Pacific/Fiji'         => "(GMT+12:00) Fiji",
);
8
  • 2
    But both Lisbon and London (although they are different timezones) share the same GMT offset and DST rules and timing, your list is full of this kind of examples...
    – Alix Axel
    Commented Oct 17, 2011 at 11:26
  • 13
    A static list of GMT offsets doesn't really help, since GMT offsets vary throughout the year based on DST. Depending on your definition the timezone then either changes to, e.g. "Europe/Berlin (DST)", or the GMT offset value of the timezone changes.
    – deceze
    Commented Apr 19, 2012 at 0:10
  • 2
    'Greenland' may need to be 'America/Godthab'.
    – JoshDM
    Commented Jul 8, 2013 at 21:02
  • 5
    Bad list. Wrong timezones identifiers!
    – Modder
    Commented Sep 10, 2015 at 12:21
  • 7
    While I like the idea that someone has gone to the trouble of providing a static list of timezone IDs and their human-readable counterpart, this is fraught with danger and it would be far better to rely on your language/framework of choice to provide you with a programmatically correct set of timezones so that when said language/framework updates you are not left with some invalid timezones (regardless of how likely/often they change)
    – simonhamp
    Commented Sep 10, 2016 at 16:19
22

A completed list, I use in my apps:

(Also check out: https://github.com/paptamas/timezones)

<?php
$timezones = 
array (
  '(GMT-12:00) International Date Line West' => 'Pacific/Wake',
  '(GMT-11:00) Midway Island' => 'Pacific/Apia',
  '(GMT-11:00) Samoa' => 'Pacific/Apia',
  '(GMT-10:00) Hawaii' => 'Pacific/Honolulu',
  '(GMT-09:00) Alaska' => 'America/Anchorage',
  '(GMT-08:00) Pacific Time (US &amp; Canada); Tijuana' => 'America/Los_Angeles',
  '(GMT-07:00) Arizona' => 'America/Phoenix',
  '(GMT-07:00) Chihuahua' => 'America/Chihuahua',
  '(GMT-07:00) La Paz' => 'America/Chihuahua',
  '(GMT-07:00) Mazatlan' => 'America/Chihuahua',
  '(GMT-07:00) Mountain Time (US &amp; Canada)' => 'America/Denver',
  '(GMT-06:00) Central America' => 'America/Managua',
  '(GMT-06:00) Central Time (US &amp; Canada)' => 'America/Chicago',
  '(GMT-06:00) Guadalajara' => 'America/Mexico_City',
  '(GMT-06:00) Mexico City' => 'America/Mexico_City',
  '(GMT-06:00) Monterrey' => 'America/Mexico_City',
  '(GMT-06:00) Saskatchewan' => 'America/Regina',
  '(GMT-05:00) Bogota' => 'America/Bogota',
  '(GMT-05:00) Eastern Time (US &amp; Canada)' => 'America/New_York',
  '(GMT-05:00) Indiana (East)' => 'America/Indiana/Indianapolis',
  '(GMT-05:00) Lima' => 'America/Bogota',
  '(GMT-05:00) Quito' => 'America/Bogota',
  '(GMT-04:00) Atlantic Time (Canada)' => 'America/Halifax',
  '(GMT-04:00) Caracas' => 'America/Caracas',
  '(GMT-04:00) La Paz' => 'America/Caracas',
  '(GMT-04:00) Santiago' => 'America/Santiago',
  '(GMT-03:30) Newfoundland' => 'America/St_Johns',
  '(GMT-03:00) Brasilia' => 'America/Sao_Paulo',
  '(GMT-03:00) Buenos Aires' => 'America/Argentina/Buenos_Aires',
  '(GMT-03:00) Georgetown' => 'America/Argentina/Buenos_Aires',
  '(GMT-03:00) Greenland' => 'America/Godthab',
  '(GMT-02:00) Mid-Atlantic' => 'America/Noronha',
  '(GMT-01:00) Azores' => 'Atlantic/Azores',
  '(GMT-01:00) Cape Verde Is.' => 'Atlantic/Cape_Verde',
  '(GMT) Casablanca' => 'Africa/Casablanca',
  '(GMT) Edinburgh' => 'Europe/London',
  '(GMT) Greenwich Mean Time : Dublin' => 'Europe/London',
  '(GMT) Lisbon' => 'Europe/London',
  '(GMT) London' => 'Europe/London',
  '(GMT) Monrovia' => 'Africa/Casablanca',
  '(GMT+01:00) Amsterdam' => 'Europe/Berlin',
  '(GMT+01:00) Belgrade' => 'Europe/Belgrade',
  '(GMT+01:00) Berlin' => 'Europe/Berlin',
  '(GMT+01:00) Bern' => 'Europe/Berlin',
  '(GMT+01:00) Bratislava' => 'Europe/Belgrade',
  '(GMT+01:00) Brussels' => 'Europe/Paris',
  '(GMT+01:00) Budapest' => 'Europe/Belgrade',
  '(GMT+01:00) Copenhagen' => 'Europe/Paris',
  '(GMT+01:00) Ljubljana' => 'Europe/Belgrade',
  '(GMT+01:00) Madrid' => 'Europe/Paris',
  '(GMT+01:00) Paris' => 'Europe/Paris',
  '(GMT+01:00) Prague' => 'Europe/Belgrade',
  '(GMT+01:00) Rome' => 'Europe/Berlin',
  '(GMT+01:00) Sarajevo' => 'Europe/Sarajevo',
  '(GMT+01:00) Skopje' => 'Europe/Sarajevo',
  '(GMT+01:00) Stockholm' => 'Europe/Berlin',
  '(GMT+01:00) Vienna' => 'Europe/Berlin',
  '(GMT+01:00) Warsaw' => 'Europe/Sarajevo',
  '(GMT+01:00) West Central Africa' => 'Africa/Lagos',
  '(GMT+01:00) Zagreb' => 'Europe/Sarajevo',
  '(GMT+02:00) Athens' => 'Europe/Istanbul',
  '(GMT+02:00) Bucharest' => 'Europe/Bucharest',
  '(GMT+02:00) Cairo' => 'Africa/Cairo',
  '(GMT+02:00) Harare' => 'Africa/Johannesburg',
  '(GMT+02:00) Helsinki' => 'Europe/Helsinki',
  '(GMT+02:00) Istanbul' => 'Europe/Istanbul',
  '(GMT+02:00) Jerusalem' => 'Asia/Jerusalem',
  '(GMT+02:00) Kyiv' => 'Europe/Helsinki',
  '(GMT+02:00) Minsk' => 'Europe/Istanbul',
  '(GMT+02:00) Pretoria' => 'Africa/Johannesburg',
  '(GMT+02:00) Riga' => 'Europe/Helsinki',
  '(GMT+02:00) Sofia' => 'Europe/Helsinki',
  '(GMT+02:00) Tallinn' => 'Europe/Helsinki',
  '(GMT+02:00) Vilnius' => 'Europe/Helsinki',
  '(GMT+03:00) Baghdad' => 'Asia/Baghdad',
  '(GMT+03:00) Kuwait' => 'Asia/Riyadh',
  '(GMT+03:00) Moscow' => 'Europe/Moscow',
  '(GMT+03:00) Nairobi' => 'Africa/Nairobi',
  '(GMT+03:00) Riyadh' => 'Asia/Riyadh',
  '(GMT+03:00) St. Petersburg' => 'Europe/Moscow',
  '(GMT+03:00) Volgograd' => 'Europe/Moscow',
  '(GMT+03:30) Tehran' => 'Asia/Tehran',
  '(GMT+04:00) Abu Dhabi' => 'Asia/Muscat',
  '(GMT+04:00) Baku' => 'Asia/Tbilisi',
  '(GMT+04:00) Muscat' => 'Asia/Muscat',
  '(GMT+04:00) Tbilisi' => 'Asia/Tbilisi',
  '(GMT+04:00) Yerevan' => 'Asia/Tbilisi',
  '(GMT+04:30) Kabul' => 'Asia/Kabul',
  '(GMT+05:00) Ekaterinburg' => 'Asia/Yekaterinburg',
  '(GMT+05:00) Islamabad' => 'Asia/Karachi',
  '(GMT+05:00) Karachi' => 'Asia/Karachi',
  '(GMT+05:00) Tashkent' => 'Asia/Karachi',
  '(GMT+05:30) Chennai' => 'Asia/Calcutta',
  '(GMT+05:30) Kolkata' => 'Asia/Calcutta',
  '(GMT+05:30) Mumbai' => 'Asia/Calcutta',
  '(GMT+05:30) New Delhi' => 'Asia/Calcutta',
  '(GMT+05:45) Kathmandu' => 'Asia/Katmandu',
  '(GMT+06:00) Almaty' => 'Asia/Novosibirsk',
  '(GMT+06:00) Astana' => 'Asia/Dhaka',
  '(GMT+06:00) Dhaka' => 'Asia/Dhaka',
  '(GMT+06:00) Novosibirsk' => 'Asia/Novosibirsk',
  '(GMT+06:00) Sri Jayawardenepura' => 'Asia/Colombo',
  '(GMT+06:30) Rangoon' => 'Asia/Rangoon',
  '(GMT+07:00) Bangkok' => 'Asia/Bangkok',
  '(GMT+07:00) Hanoi' => 'Asia/Bangkok',
  '(GMT+07:00) Jakarta' => 'Asia/Bangkok',
  '(GMT+07:00) Krasnoyarsk' => 'Asia/Krasnoyarsk',
  '(GMT+08:00) Beijing' => 'Asia/Hong_Kong',
  '(GMT+08:00) Chongqing' => 'Asia/Hong_Kong',
  '(GMT+08:00) Hong Kong' => 'Asia/Hong_Kong',
  '(GMT+08:00) Irkutsk' => 'Asia/Irkutsk',
  '(GMT+08:00) Kuala Lumpur' => 'Asia/Singapore',
  '(GMT+08:00) Perth' => 'Australia/Perth',
  '(GMT+08:00) Singapore' => 'Asia/Singapore',
  '(GMT+08:00) Taipei' => 'Asia/Taipei',
  '(GMT+08:00) Ulaan Bataar' => 'Asia/Irkutsk',
  '(GMT+08:00) Urumqi' => 'Asia/Hong_Kong',
  '(GMT+09:00) Osaka' => 'Asia/Tokyo',
  '(GMT+09:00) Sapporo' => 'Asia/Tokyo',
  '(GMT+09:00) Seoul' => 'Asia/Seoul',
  '(GMT+09:00) Tokyo' => 'Asia/Tokyo',
  '(GMT+09:00) Yakutsk' => 'Asia/Yakutsk',
  '(GMT+09:30) Adelaide' => 'Australia/Adelaide',
  '(GMT+09:30) Darwin' => 'Australia/Darwin',
  '(GMT+10:00) Brisbane' => 'Australia/Brisbane',
  '(GMT+10:00) Canberra' => 'Australia/Sydney',
  '(GMT+10:00) Guam' => 'Pacific/Guam',
  '(GMT+10:00) Hobart' => 'Australia/Hobart',
  '(GMT+10:00) Melbourne' => 'Australia/Sydney',
  '(GMT+10:00) Port Moresby' => 'Pacific/Guam',
  '(GMT+10:00) Sydney' => 'Australia/Sydney',
  '(GMT+10:00) Vladivostok' => 'Asia/Vladivostok',
  '(GMT+11:00) Magadan' => 'Asia/Magadan',
  '(GMT+11:00) New Caledonia' => 'Asia/Magadan',
  '(GMT+11:00) Solomon Is.' => 'Asia/Magadan',
  '(GMT+12:00) Auckland' => 'Pacific/Auckland',
  '(GMT+12:00) Fiji' => 'Pacific/Fiji',
  '(GMT+12:00) Kamchatka' => 'Pacific/Fiji',
  '(GMT+12:00) Marshall Is.' => 'Pacific/Fiji',
  '(GMT+12:00) Wellington' => 'Pacific/Auckland',
  '(GMT+13:00) Nuku\'alofa' => 'Pacific/Tongatapu',
);
?>

It is very important to store timezone identifiers in your database and not just the timezone offset like "GMT+2", because of Daylight Saving Times.

5
  • I was comparing some of those values to what Windows 7 uses and some of them aren't the same... Like Georgetown. You say -3, Windows -4. I have no idea and I don't want to look each difference up. Just a warning. I'm not saying you're wrong, I'm not saying Windows is, or maybe they're the same and I'm confused. It's all possible. Just a warning to other people trying to solve the issue of ugly PHP timezone text. Commented Feb 11, 2013 at 22:23
  • Thank you for feedback. There is no problem with the list, but the problem is a little bit complex. I am from Romania, and my timezone is Europe/Bucharest. In windows now it appears UTC+2 Athens/Bucharest, but 3 months ago appeared UTC+3 Athens/Bucharest because of the Daylight Saving Time.
    – Tamás Pap
    Commented Feb 11, 2013 at 22:34
  • omg, yes, this is such a crazy problem. I haven't found a solution I like yet... I found this: unicode.org/repos/cldr/trunk/common/supplemental/… which is cool... but... not what I want. I guess the reasoning behind all this is because "pretty" Windows text that we all want is sometimes a list of cities, that may change, and each timezone needs to be represented in the whole list which is managed by Microsoft. And it would be time consuming (haha...) to maintain a mapping btwn Windows and Olson, which everything else uses... Commented Feb 11, 2013 at 23:04
  • 1
    Yeah, it's a crazy one :) I think using this list is fine! Many big companies uses it like 37signals, Harvest, etc. You will store in db, and make your calculations based on the timezone identifiers like Europe/Paris, and you shouldn't take care much about if it's UTM+1 or UTM+2 at the moment. Everybody will find his timezone pretty easy. Just don't waste your time with this, focus on real problems. :) Cheers!
    – Tamás Pap
    Commented Feb 11, 2013 at 23:28
  • doesn't have all the available timezones
    – EnexoOnoma
    Commented Dec 18, 2019 at 10:40
21

if you are looking to generate a similar timezone list as give in the image below

Timezone Dropdown list

You can use the following php code to generate the dropdown list using the DateTimeZone::listIdentifiers -- timezone_identifiers_list — Returns a numerically indexed array containing all defined timezone identifiers.If you want a list of ALL possible values (including backwards compatible aliases), use DateTimeZone::ALL_WITH_BC in place of DateTimeZone::ALL

echo "<select>";
$tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
foreach($tzlist as $value)
{
  echo "<option value=". $value .">". $value ."</option>";
}
echo "<select>";
2
  • 8
    Jedi arm move.... This is the right answer that people are looking for Commented Aug 6, 2020 at 5:26
  • it just doesn't have the +Time
    – Mac A.
    Commented Aug 23, 2021 at 6:43
6

Try the following code from How do I get Greenwich Mean Time in PHP?. I use it on one of my apps, but you can change the markup to display whatever you want:

public function tz_list() {
    $zones_array = array();
    $timestamp = time();
    foreach(timezone_identifiers_list() as $key => $zone) {
      date_default_timezone_set($zone);
      $zones_array[$key]['zone'] = $zone;
      $zones_array[$key]['offset'] = (int) ((int) date('O', $timestamp))/100;
      $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
    }
    return $zones_array;
}

Then:

<select name="timezone" id="timezone" class="form-control">
  <option value="">Select a time zone</option>
  <?php foreach(tz_list() as $t) { ?>
      <option value="<?php echo $t['offset']; ?>___<?php echo $t['zone']; ?>" 
      <?php echo $t['diff_from_GMT'] . ' - ' . $t['zone']; ?></option>
  <?php } ?>
</select>
2
  • 1
    This is globally setting the timezone as you iterate. You are better off using the DateTime and DateTimeZone classes Commented May 21, 2019 at 6:59
  • @MeatPopsicle global for the duration of the request and only your request - not on the server. Why would you think we are better off using DateTime in this case? Commented May 22, 2019 at 8:08
6

This is the solution that I find better than a hardcoded array, because offsets are calculated dynamically.

<?php 
            function toGmtOffset($timezone){
                  $userTimeZone = new DateTimeZone($timezone);
                  $offset = $userTimeZone->getOffset(new DateTime("now",new DateTimeZone('GMT'))); // Offset in seconds
                  $seconds = abs($offset);
                  $sign = $offset > 0 ? '+' : '-';
                  $hours = floor($seconds / 3600);
                  $mins = floor($seconds / 60 % 60);
                  $secs = floor($seconds % 60);
                  return sprintf("(GMT$sign%02d:%02d)", $hours, $mins, $secs);
            }
            $timezones = array(
            'Pacific/Midway'       => toGmtOffset('Pacific/Midway'       ). " Midway Island",
            'US/Samoa'             => toGmtOffset('US/Samoa'             ). " Samoa",
            'US/Hawaii'            => toGmtOffset('US/Hawaii'            ). " Hawaii",
            'US/Alaska'            => toGmtOffset('US/Alaska'            ). " Alaska",
            'US/Pacific'           => toGmtOffset('US/Pacific'           ). " Pacific Time (US &amp; Canada)",
            'America/Tijuana'      => toGmtOffset('America/Tijuana'      ). " Tijuana",
            'US/Arizona'           => toGmtOffset('US/Arizona'           ). " Arizona",
            'US/Mountain'          => toGmtOffset('US/Mountain'          ). " Mountain Time (US &amp; Canada)",
            'America/Chihuahua'    => toGmtOffset('America/Chihuahua'    ). " Chihuahua",
            'America/Mazatlan'     => toGmtOffset('America/Mazatlan'     ). " Mazatlan",
            'America/Mexico_City'  => toGmtOffset('America/Mexico_City'  ). " Mexico City",
            'America/Monterrey'    => toGmtOffset('America/Monterrey'    ). " Monterrey",
            'Canada/Saskatchewan'  => toGmtOffset('Canada/Saskatchewan'  ). " Saskatchewan",
            'US/Central'           => toGmtOffset('US/Central'           ). " Central Time (US &amp; Canada)",
            'US/Eastern'           => toGmtOffset('US/Eastern'           ). " Eastern Time (US &amp; Canada)",
            'US/East-Indiana'      => toGmtOffset('US/East-Indiana'      ). " Indiana (East)",
            'America/Bogota'       => toGmtOffset('America/Bogota'       ). " Bogota",
            'America/Lima'         => toGmtOffset('America/Lima'         ). " Lima",
            'America/Caracas'      => toGmtOffset('America/Caracas'      ). " Caracas",
            'Canada/Atlantic'      => toGmtOffset('Canada/Atlantic'      ). " Atlantic Time (Canada)",
            'America/La_Paz'       => toGmtOffset('America/La_Paz'       ). " La Paz",
            'America/Santiago'     => toGmtOffset('America/Santiago'     ). " Santiago",
            'Canada/Newfoundland'  => toGmtOffset('Canada/Newfoundland'  ). " Newfoundland",
            'America/Buenos_Aires' => toGmtOffset('America/Buenos_Aires' ). " Buenos Aires",
            'Atlantic/Stanley'     => toGmtOffset('Atlantic/Stanley'     ). " Stanley",
            'Atlantic/Azores'      => toGmtOffset('Atlantic/Azores'      ). " Azores",
            'Atlantic/Cape_Verde'  => toGmtOffset('Atlantic/Cape_Verde'  ). " Cape Verde Is.",
            'Africa/Casablanca'    => toGmtOffset('Africa/Casablanca'    ). " Casablanca",
            'Europe/Dublin'        => toGmtOffset('Europe/Dublin'        ). " Dublin",
            'Europe/Lisbon'        => toGmtOffset('Europe/Lisbon'        ). " Lisbon",
            'Europe/London'        => toGmtOffset('Europe/London'        ). " London",
            'Africa/Monrovia'      => toGmtOffset('Africa/Monrovia'      ). " Monrovia",
            'Europe/Amsterdam'     => toGmtOffset('Europe/Amsterdam'     ). " Amsterdam",
            'Europe/Belgrade'      => toGmtOffset('Europe/Belgrade'      ). " Belgrade",
            'Europe/Berlin'        => toGmtOffset('Europe/Berlin'        ). " Berlin",
            'Europe/Bratislava'    => toGmtOffset('Europe/Bratislava'    ). " Bratislava",
            'Europe/Brussels'      => toGmtOffset('Europe/Brussels'      ). " Brussels",
            'Europe/Budapest'      => toGmtOffset('Europe/Budapest'      ). " Budapest",
            'Europe/Copenhagen'    => toGmtOffset('Europe/Copenhagen'    ). " Copenhagen",
            'Europe/Ljubljana'     => toGmtOffset('Europe/Ljubljana'     ). " Ljubljana",
            'Europe/Madrid'        => toGmtOffset('Europe/Madrid'        ). " Madrid",
            'Europe/Paris'         => toGmtOffset('Europe/Paris'         ). " Paris",
            'Europe/Prague'        => toGmtOffset('Europe/Prague'        ). " Prague",
            'Europe/Rome'          => toGmtOffset('Europe/Rome'          ). " Rome",
            'Europe/Sarajevo'      => toGmtOffset('Europe/Sarajevo'      ). " Sarajevo",
            'Europe/Skopje'        => toGmtOffset('Europe/Skopje'        ). " Skopje",
            'Europe/Stockholm'     => toGmtOffset('Europe/Stockholm'     ). " Stockholm",
            'Europe/Vienna'        => toGmtOffset('Europe/Vienna'        ). " Vienna",
            'Europe/Warsaw'        => toGmtOffset('Europe/Warsaw'        ). " Warsaw",
            'Europe/Zagreb'        => toGmtOffset('Europe/Zagreb'        ). " Zagreb",
            'Europe/Athens'        => toGmtOffset('Europe/Athens'        ). " Athens",
            'Europe/Bucharest'     => toGmtOffset('Europe/Bucharest'     ). " Bucharest",
            'Africa/Cairo'         => toGmtOffset('Africa/Cairo'         ). " Cairo",
            'Africa/Harare'        => toGmtOffset('Africa/Harare'        ). " Harare",
            'Europe/Helsinki'      => toGmtOffset('Europe/Helsinki'      ). " Helsinki",
            'Europe/Istanbul'      => toGmtOffset('Europe/Istanbul'      ). " Istanbul",
            'Asia/Jerusalem'       => toGmtOffset('Asia/Jerusalem'       ). " Jerusalem",
            'Europe/Kiev'          => toGmtOffset('Europe/Kiev'          ). " Kyiv",
            'Europe/Minsk'         => toGmtOffset('Europe/Minsk'         ). " Minsk",
            'Europe/Riga'          => toGmtOffset('Europe/Riga'          ). " Riga",
            'Europe/Sofia'         => toGmtOffset('Europe/Sofia'         ). " Sofia",
            'Europe/Tallinn'       => toGmtOffset('Europe/Tallinn'       ). " Tallinn",
            'Europe/Vilnius'       => toGmtOffset('Europe/Vilnius'       ). " Vilnius",
            'Asia/Baghdad'         => toGmtOffset('Asia/Baghdad'         ). " Baghdad",
            'Asia/Kuwait'          => toGmtOffset('Asia/Kuwait'          ). " Kuwait",
            'Africa/Nairobi'       => toGmtOffset('Africa/Nairobi'       ). " Nairobi",
            'Asia/Riyadh'          => toGmtOffset('Asia/Riyadh'          ). " Riyadh",
            'Europe/Moscow'        => toGmtOffset('Europe/Moscow'        ). " Moscow",
            'Asia/Tehran'          => toGmtOffset('Asia/Tehran'          ). " Tehran",
            'Asia/Baku'            => toGmtOffset('Asia/Baku'            ). " Baku",
            'Europe/Volgograd'     => toGmtOffset('Europe/Volgograd'     ). " Volgograd",
            'Asia/Muscat'          => toGmtOffset('Asia/Muscat'          ). " Muscat",
            'Asia/Tbilisi'         => toGmtOffset('Asia/Tbilisi'         ). " Tbilisi",
            'Asia/Yerevan'         => toGmtOffset('Asia/Yerevan'         ). " Yerevan",
            'Asia/Kabul'           => toGmtOffset('Asia/Kabul'           ). " Kabul",
            'Asia/Karachi'         => toGmtOffset('Asia/Karachi'         ). " Karachi",
            'Asia/Tashkent'        => toGmtOffset('Asia/Tashkent'        ). " Tashkent",
            'Asia/Kolkata'         => toGmtOffset('Asia/Kolkata'         ). " Kolkata",
            'Asia/Kathmandu'       => toGmtOffset('Asia/Kathmandu'       ). " Kathmandu",
            'Asia/Yekaterinburg'   => toGmtOffset('Asia/Yekaterinburg'   ). " Ekaterinburg",
            'Asia/Almaty'          => toGmtOffset('Asia/Almaty'          ). " Almaty",
            'Asia/Dhaka'           => toGmtOffset('Asia/Dhaka'           ). " Dhaka",
            'Asia/Novosibirsk'     => toGmtOffset('Asia/Novosibirsk'     ). " Novosibirsk",
            'Asia/Bangkok'         => toGmtOffset('Asia/Bangkok'         ). " Bangkok",
            'Asia/Jakarta'         => toGmtOffset('Asia/Jakarta'         ). " Jakarta",
            'Asia/Krasnoyarsk'     => toGmtOffset('Asia/Krasnoyarsk'     ). " Krasnoyarsk",
            'Asia/Chongqing'       => toGmtOffset('Asia/Chongqing'       ). " Chongqing",
            'Asia/Hong_Kong'       => toGmtOffset('Asia/Hong_Kong'       ). " Hong Kong",
            'Asia/Kuala_Lumpur'    => toGmtOffset('Asia/Kuala_Lumpur'    ). " Kuala Lumpur",
            'Australia/Perth'      => toGmtOffset('Australia/Perth'      ). " Perth",
            'Asia/Singapore'       => toGmtOffset('Asia/Singapore'       ). " Singapore",
            'Asia/Taipei'          => toGmtOffset('Asia/Taipei'          ). " Taipei",
            'Asia/Ulaanbaatar'     => toGmtOffset('Asia/Ulaanbaatar'     ). " Ulaan Bataar",
            'Asia/Urumqi'          => toGmtOffset('Asia/Urumqi'          ). " Urumqi",
            'Asia/Irkutsk'         => toGmtOffset('Asia/Irkutsk'         ). " Irkutsk",
            'Asia/Seoul'           => toGmtOffset('Asia/Seoul'           ). " Seoul",
            'Asia/Tokyo'           => toGmtOffset('Asia/Tokyo'           ). " Tokyo",
            'Australia/Adelaide'   => toGmtOffset('Australia/Adelaide'   ). " Adelaide",
            'Australia/Darwin'     => toGmtOffset('Australia/Darwin'     ). " Darwin",
            'Asia/Yakutsk'         => toGmtOffset('Asia/Yakutsk'         ). " Yakutsk",
            'Australia/Brisbane'   => toGmtOffset('Australia/Brisbane'   ). " Brisbane",
            'Australia/Canberra'   => toGmtOffset('Australia/Canberra'   ). " Canberra",
            'Pacific/Guam'         => toGmtOffset('Pacific/Guam'         ). " Guam",
            'Australia/Hobart'     => toGmtOffset('Australia/Hobart'     ). " Hobart",
            'Australia/Melbourne'  => toGmtOffset('Australia/Melbourne'  ). " Melbourne",
            'Pacific/Port_Moresby' => toGmtOffset('Pacific/Port_Moresby' ). " Port Moresby",
            'Australia/Sydney'     => toGmtOffset('Australia/Sydney'     ). " Sydney",
            'Asia/Vladivostok'     => toGmtOffset('Asia/Vladivostok'     ). " Vladivostok",
            'Asia/Magadan'         => toGmtOffset('Asia/Magadan'         ). " Magadan",
            'Pacific/Auckland'     => toGmtOffset('Pacific/Auckland'     ). " Auckland",
            'Pacific/Fiji'         => toGmtOffset('Pacific/Fiji'         ). " Fiji",
            );
5

from @chpx 's answer:

function getAllTimeZones(){

$selectOptions = "";

    foreach(\DateTimeZone::listIdentifiers() as  $zoneLabel)
    {
        $currentTimeInZone = new \DateTime("now", new \DateTimeZone($zoneLabel));
        $currentTimeDiff = $currentTimeInZone->format('P');
        $selectOptions .= "<option value=\"$zoneLabel\">(GMT $currentTimeDiff) $zoneLabel</option>\n";
    }

return $selectOptions;
}
5

Added missing countries to the existing answers

        $country_timezone = array(
            'Asia/Kabul' => 'Afghanistan',
            'Europe/Tirane' => 'Albania',
            'Africa/Algiers' => 'Algeria',
            'Pacific/Pago_Pago' => 'American Samoa',
            'Europe/Andorra' => 'Andorra',
            'Africa/Luanda' => 'Angola',
            'America/Anguilla' => 'Anguilla',
            'Antarctica/Casey' => 'Antarctica',
            'Antarctica/Davis' => 'Antarctica',
            'Antarctica/DumontDUrville' => 'Antarctica',
            'Antarctica/Mawson' => 'Antarctica',
            'Antarctica/McMurdo' => 'Antarctica',
            'Antarctica/Palmer' => 'Antarctica',
            'Antarctica/Rothera' => 'Antarctica',
            'Antarctica/Syowa' => 'Antarctica',
            'Antarctica/Troll' => 'Antarctica',
            'Antarctica/Vostok' => 'Antarctica',
            'America/Antigua' => 'Antigua and Barbuda',
            'America/Argentina/Buenos_Aires' => 'Argentina',
            'America/Argentina/Catamarca' => 'Argentina',
            'America/Argentina/Cordoba' => 'Argentina',
            'America/Argentina/Jujuy' => 'Argentina',
            'America/Argentina/La_Rioja' => 'Argentina',
            'America/Argentina/Mendoza' => 'Argentina',
            'America/Argentina/Rio_Gallegos' => 'Argentina',
            'America/Argentina/Salta' => 'Argentina',
            'America/Argentina/San_Juan' => 'Argentina',
            'America/Argentina/San_Luis' => 'Argentina',
            'America/Argentina/Tucuman' => 'Argentina',
            'America/Argentina/Ushuaia' => 'Argentina',
            'Asia/Yerevan' => 'Armenia',
            'America/Aruba' => 'Aruba',
            'Antarctica/Macquarie' => 'Australia',
            'Australia/Adelaide' => 'Australia',
            'Australia/Brisbane' => 'Australia',
            'Australia/Broken_Hill' => 'Australia',
            'Australia/Darwin' => 'Australia',
            'Australia/Eucla' => 'Australia',
            'Australia/Hobart' => 'Australia',
            'Australia/Lindeman' => 'Australia',
            'Australia/Lord_Howe' => 'Australia',
            'Australia/Melbourne' => 'Australia',
            'Australia/Perth' => 'Australia',
            'Australia/Sydney' => 'Australia',
            'Europe/Vienna' => 'Austria',
            'Asia/Baku' => 'Azerbaijan',
            'America/Nassau' => 'Bahamas',
            'Asia/Bahrain' => 'Bahrain',
            'Asia/Dhaka' => 'Bangladesh',
            'America/Barbados' => 'Barbados',
            'Europe/Minsk' => 'Belarus',
            'Europe/Brussels' => 'Belgium',
            'America/Belize' => 'Belize',
            'Africa/Porto-Novo' => 'Benin',
            'Atlantic/Bermuda' => 'Bermuda',
            'Asia/Thimphu' => 'Bhutan',
            'Plurinational State of' => 'Bolivia',
            'Sint Eustatius and Saba' => 'Bonaire',
            'Europe/Sarajevo' => 'Bosnia and Herzegovina',
            'Africa/Gaborone' => 'Botswana',
            'America/Araguaina' => 'Brazil',
            'America/Bahia' => 'Brazil',
            'America/Belem' => 'Brazil',
            'America/Boa_Vista' => 'Brazil',
            'America/Campo_Grande' => 'Brazil',
            'America/Cuiaba' => 'Brazil',
            'America/Eirunepe' => 'Brazil',
            'America/Fortaleza' => 'Brazil',
            'America/Maceio' => 'Brazil',
            'America/Manaus' => 'Brazil',
            'America/Noronha' => 'Brazil',
            'America/Porto_Velho' => 'Brazil',
            'America/Recife' => 'Brazil',
            'America/Rio_Branco' => 'Brazil',
            'America/Santarem' => 'Brazil',
            'America/Sao_Paulo' => 'Brazil',
            'Indian/Chagos' => 'British Indian Ocean Territory',
            'Asia/Brunei' => 'Brunei Darussalam',
            'Europe/Sofia' => 'Bulgaria',
            'Africa/Ouagadougou' => 'Burkina Faso',
            'Africa/Bujumbura' => 'Burundi',
            'Asia/Phnom_Penh' => 'Cambodia',
            'Africa/Douala' => 'Cameroon',
            'America/Atikokan' => 'Canada',
            'America/Blanc-Sablon' => 'Canada',
            'America/Cambridge_Bay' => 'Canada',
            'America/Creston' => 'Canada',
            'America/Dawson' => 'Canada',
            'America/Dawson_Creek' => 'Canada',
            'America/Edmonton' => 'Canada',
            'America/Fort_Nelson' => 'Canada',
            'America/Glace_Bay' => 'Canada',
            'America/Goose_Bay' => 'Canada',
            'America/Halifax' => 'Canada',
            'America/Inuvik' => 'Canada',
            'America/Iqaluit' => 'Canada',
            'America/Moncton' => 'Canada',
            'America/Nipigon' => 'Canada',
            'America/Pangnirtung' => 'Canada',
            'America/Rainy_River' => 'Canada',
            'America/Rankin_Inlet' => 'Canada',
            'America/Regina' => 'Canada',
            'America/Resolute' => 'Canada',
            'America/St_Johns' => 'Canada',
            'America/Swift_Current' => 'Canada',
            'America/Thunder_Bay' => 'Canada',
            'America/Toronto' => 'Canada',
            'America/Vancouver' => 'Canada',
            'America/Whitehorse' => 'Canada',
            'America/Winnipeg' => 'Canada',
            'America/Yellowknife' => 'Canada',
            'Atlantic/Cape_Verde' => 'Cape Verde',
            'America/Cayman' => 'Cayman Islands',
            'Africa/Bangui' => 'Central African Republic',
            'Africa/Ndjamena' => 'Chad',
            'America/Punta_Arenas' => 'Chile',
            'America/Santiago' => 'Chile',
            'Pacific/Easter' => 'Chile',
            'Asia/Shanghai' => 'China',
            'Asia/Urumqi' => 'China',
            'Indian/Christmas' => 'Christmas Island',
            'Indian/Cocos' => 'Cocos (Keeling) Islands',
            'America/Bogota' => 'Colombia',
            'Indian/Comoro' => 'Comoros',
            'Pacific/Rarotonga' => 'Cook Islands',
            'America/Costa_Rica' => 'Costa Rica',
            'Europe/Zagreb' => 'Croatia',
            'America/Havana' => 'Cuba',
            'America/Curacao' => 'Curaçao',
            'Asia/Famagusta' => 'Cyprus',
            'Asia/Nicosia' => 'Cyprus',
            'Europe/Prague' => 'Czech Republic',
            'Africa/Abidjan' => 'Côte d Ivoire',
            'Europe/Copenhagen' => 'Denmark',
            'Africa/Djibouti' => 'Djibouti',
            'America/Dominica' => 'Dominica',
            'America/Santo_Domingo' => 'Dominican Republic',
            'America/Guayaquil' => 'Ecuador',
            'Pacific/Galapagos' => 'Ecuador',
            'Africa/Cairo' => 'Egypt',
            'America/El_Salvador' => 'El Salvador',
            'Africa/Malabo' => 'Equatorial Guinea',
            'Africa/Asmara' => 'Eritrea',
            'Europe/Tallinn' => 'Estonia',
            'Africa/Addis_Ababa' => 'Ethiopia',
            'Atlantic/Stanley' => 'Falkland Islands (Malvinas)',
            'Atlantic/Faroe' => 'Faroe Islands',
            'Pacific/Fiji' => 'Fiji',
            'Europe/Helsinki' => 'Finland',
            'Europe/Paris' => 'France',
            'America/Cayenne' => 'French Guiana',
            'Pacific/Gambier' => 'French Polynesia',
            'Pacific/Marquesas' => 'French Polynesia',
            'Pacific/Tahiti' => 'French Polynesia',
            'Indian/Kerguelen' => 'French Southern Territories',
            'Africa/Libreville' => 'Gabon',
            'Africa/Banjul' => 'Gambia',
            'Asia/Tbilisi' => 'Georgia',
            'Europe/Berlin' => 'Germany',
            'Europe/Busingen' => 'Germany',
            'Africa/Accra' => 'Ghana',
            'Europe/Gibraltar' => 'Gibraltar',
            'Europe/Athens' => 'Greece',
            'America/Danmarkshavn' => 'Greenland',
            'America/Nuuk' => 'Greenland',
            'America/Scoresbysund' => 'Greenland',
            'America/Thule' => 'Greenland',
            'America/Grenada' => 'Grenada',
            'America/Guadeloupe' => 'Guadeloupe',
            'Pacific/Guam' => 'Guam',
            'America/Guatemala' => 'Guatemala',
            'Europe/Guernsey' => 'Guernsey',
            'Africa/Conakry' => 'Guinea',
            'Africa/Bissau' => 'Guinea-Bissau',
            'America/Guyana' => 'Guyana',
            'America/Port-au-Prince' => 'Haiti',
            'Europe/Vatican' => 'Holy See (Vatican City State)',
            'America/Tegucigalpa' => 'Honduras',
            'Asia/Hong_Kong' => 'Hong Kong',
            'Europe/Budapest' => 'Hungary',
            'Atlantic/Reykjavik' => 'Iceland',
            'Asia/Kolkata' => 'India',
            'Asia/Jakarta' => 'Indonesia',
            'Asia/Jayapura' => 'Indonesia',
            'Asia/Makassar' => 'Indonesia',
            'Asia/Pontianak' => 'Indonesia',
            'Islamic Republic of' => 'Iran',
            'Asia/Baghdad' => 'Iraq',
            'Europe/Dublin' => 'Ireland',
            'Europe/Isle_of_Man' => 'Isle of Man',
            'Asia/Jerusalem' => 'Israel',
            'Europe/Rome' => 'Italy',
            'America/Jamaica' => 'Jamaica',
            'Asia/Tokyo' => 'Japan',
            'Europe/Jersey' => 'Jersey',
            'Asia/Amman' => 'Jordan',
            'Asia/Almaty' => 'Kazakhstan',
            'Asia/Aqtau' => 'Kazakhstan',
            'Asia/Aqtobe' => 'Kazakhstan',
            'Asia/Atyrau' => 'Kazakhstan',
            'Asia/Oral' => 'Kazakhstan',
            'Asia/Qostanay' => 'Kazakhstan',
            'Asia/Qyzylorda' => 'Kazakhstan',
            'Africa/Nairobi' => 'Kenya',
            'Pacific/Kanton' => 'Kiribati',
            'Pacific/Kiritimati' => 'Kiribati',
            'Pacific/Tarawa' => 'Kiribati',
            'Democratic Peoples Republic of' => 'Korea',
            'Asia/Kuwait' => 'Kuwait',
            'Asia/Bishkek' => 'Kyrgyzstan',
            'Asia/Vientiane' => 'Lao Peoples Democratic Republic',
            'Europe/Riga' => 'Latvia',
            'Asia/Beirut' => 'Lebanon',
            'Africa/Maseru' => 'Lesotho',
            'Africa/Monrovia' => 'Liberia',
            'Africa/Tripoli' => 'Libya',
            'Europe/Vaduz' => 'Liechtenstein',
            'Europe/Vilnius' => 'Lithuania',
            'Europe/Luxembourg' => 'Luxembourg',
            'Asia/Macau' => 'Macao',
            'the Former Yugoslav Republic of' => 'Macedonia',
            'Indian/Antananarivo' => 'Madagascar',
            'Africa/Blantyre' => 'Malawi',
            'Asia/Kuala_Lumpur' => 'Malaysia',
            'Asia/Kuching' => 'Malaysia',
            'Indian/Maldives' => 'Maldives',
            'Africa/Bamako' => 'Mali',
            'Europe/Malta' => 'Malta',
            'Pacific/Kwajalein' => 'Marshall Islands',
            'Pacific/Majuro' => 'Marshall Islands',
            'America/Martinique' => 'Martinique',
            'Africa/Nouakchott' => 'Mauritania',
            'Indian/Mauritius' => 'Mauritius',
            'Indian/Mayotte' => 'Mayotte',
            'America/Bahia_Banderas' => 'Mexico',
            'America/Cancun' => 'Mexico',
            'America/Chihuahua' => 'Mexico',
            'America/Hermosillo' => 'Mexico',
            'America/Matamoros' => 'Mexico',
            'America/Mazatlan' => 'Mexico',
            'America/Merida' => 'Mexico',
            'America/Mexico_City' => 'Mexico',
            'America/Monterrey' => 'Mexico',
            'America/Ojinaga' => 'Mexico',
            'America/Tijuana' => 'Mexico',
            'Europe/Monaco' => 'Monaco',
            'Asia/Choibalsan' => 'Mongolia',
            'Asia/Hovd' => 'Mongolia',
            'Asia/Ulaanbaatar' => 'Mongolia',
            'Europe/Podgorica' => 'Montenegro',
            'America/Montserrat' => 'Montserrat',
            'Africa/Casablanca' => 'Morocco',
            'Africa/Maputo' => 'Mozambique',
            'Asia/Yangon' => 'Myanmar',
            'Africa/Windhoek' => 'Namibia',
            'Pacific/Nauru' => 'Nauru',
            'Asia/Kathmandu' => 'Nepal',
            'Europe/Amsterdam' => 'Netherlands',
            'Pacific/Noumea' => 'New Caledonia',
            'Pacific/Auckland' => 'New Zealand',
            'Pacific/Chatham' => 'New Zealand',
            'America/Managua' => 'Nicaragua',
            'Africa/Niamey' => 'Niger',
            'Africa/Lagos' => 'Nigeria',
            'Pacific/Niue' => 'Niue',
            'Pacific/Norfolk' => 'Norfolk Island',
            'Pacific/Saipan' => 'Northern Mariana Islands',
            'Europe/Oslo' => 'Norway',
            'Asia/Muscat' => 'Oman',
            'Asia/Karachi' => 'Pakistan',
            'Pacific/Palau' => 'Palau',
            'America/Panama' => 'Panama',
            'Pacific/Bougainville' => 'Papua New Guinea',
            'Pacific/Port_Moresby' => 'Papua New Guinea',
            'America/Asuncion' => 'Paraguay',
            'America/Lima' => 'Peru',
            'Asia/Manila' => 'Philippines',
            'Pacific/Pitcairn' => 'Pitcairn',
            'Europe/Warsaw' => 'Poland',
            'Atlantic/Azores' => 'Portugal',
            'Atlantic/Madeira' => 'Portugal',
            'Europe/Lisbon' => 'Portugal',
            'America/Puerto_Rico' => 'Puerto Rico',
            'Asia/Qatar' => 'Qatar',
            'Europe/Bucharest' => 'Romania',
            'Asia/Anadyr' => 'Russian Federation',
            'Asia/Barnaul' => 'Russian Federation',
            'Asia/Chita' => 'Russian Federation',
            'Asia/Irkutsk' => 'Russian Federation',
            'Asia/Kamchatka' => 'Russian Federation',
            'Asia/Khandyga' => 'Russian Federation',
            'Asia/Krasnoyarsk' => 'Russian Federation',
            'Asia/Magadan' => 'Russian Federation',
            'Asia/Novokuznetsk' => 'Russian Federation',
            'Asia/Novosibirsk' => 'Russian Federation',
            'Asia/Omsk' => 'Russian Federation',
            'Asia/Sakhalin' => 'Russian Federation',
            'Asia/Srednekolymsk' => 'Russian Federation',
            'Asia/Tomsk' => 'Russian Federation',
            'Asia/Ust-Nera' => 'Russian Federation',
            'Asia/Vladivostok' => 'Russian Federation',
            'Asia/Yakutsk' => 'Russian Federation',
            'Asia/Yekaterinburg' => 'Russian Federation',
            'Europe/Astrakhan' => 'Russian Federation',
            'Europe/Kaliningrad' => 'Russian Federation',
            'Europe/Kirov' => 'Russian Federation',
            'Europe/Moscow' => 'Russian Federation',
            'Europe/Samara' => 'Russian Federation',
            'Europe/Saratov' => 'Russian Federation',
            'Europe/Ulyanovsk' => 'Russian Federation',
            'Europe/Volgograd' => 'Russian Federation',
            'Africa/Kigali' => 'Rwanda',
            'Indian/Reunion' => 'Réunion',
            'America/St_Barthelemy' => 'Saint Barthélemy',
            'Ascension and Tristan da Cunha' => 'Saint Helena',
            'America/St_Kitts' => 'Saint Kitts and Nevis',
            'America/St_Lucia' => 'Saint Lucia',
            'America/Marigot' => 'Saint Martin (French part)',
            'America/Miquelon' => 'Saint Pierre and Miquelon',
            'America/St_Vincent' => 'Saint Vincent and the Grenadines',
            'Pacific/Apia' => 'Samoa',
            'Europe/San_Marino' => 'San Marino',
            'Africa/Sao_Tome' => 'Sao Tome and Principe',
            'Asia/Riyadh' => 'Saudi Arabia',
            'Africa/Dakar' => 'Senegal',
            'Europe/Belgrade' => 'Serbia',
            'Indian/Mahe' => 'Seychelles',
            'Africa/Freetown' => 'Sierra Leone',
            'Asia/Singapore' => 'Singapore',
            'America/Lower_Princes' => 'Sint Maarten (Dutch part)',
            'Europe/Bratislava' => 'Slovakia',
            'Europe/Ljubljana' => 'Slovenia',
            'Pacific/Guadalcanal' => 'Solomon Islands',
            'Africa/Mogadishu' => 'Somalia',
            'Africa/Johannesburg' => 'South Africa',
            'Atlantic/South_Georgia' => 'South Georgia and the South Sandwich Islands',
            'Africa/Juba' => 'South Sudan',
            'Africa/Ceuta' => 'Spain',
            'Atlantic/Canary' => 'Spain',
            'Europe/Madrid' => 'Spain',
            'Asia/Colombo' => 'Sri Lanka',
            'Africa/Khartoum' => 'Sudan',
            'America/Paramaribo' => 'Suriname',
            'Arctic/Longyearbyen' => 'Svalbard and Jan Mayen',
            'Africa/Mbabane' => 'Swaziland',
            'Europe/Stockholm' => 'Sweden',
            'Europe/Zurich' => 'Switzerland',
            'Asia/Damascus' => 'Syrian Arab Republic',
            'Province of China' => 'Taiwan',
            'Asia/Dushanbe' => 'Tajikistan',
            'United Republic of' => 'Tanzania',
            'Asia/Bangkok' => 'Thailand',
            'Asia/Dili' => 'Timor-Leste',
            'Africa/Lome' => 'Togo',
            'Pacific/Fakaofo' => 'Tokelau',
            'Pacific/Tongatapu' => 'Tonga',
            'America/Port_of_Spain' => 'Trinidad and Tobago',
            'Africa/Tunis' => 'Tunisia',
            'Europe/Istanbul' => 'Turkey',
            'Asia/Ashgabat' => 'Turkmenistan',
            'America/Grand_Turk' => 'Turks and Caicos Islands',
            'Pacific/Funafuti' => 'Tuvalu',
            'Africa/Kampala' => 'Uganda',
            'Europe/Kiev' => 'Ukraine',
            'Europe/Simferopol' => 'Ukraine',
            'Europe/Uzhgorod' => 'Ukraine',
            'Europe/Zaporozhye' => 'Ukraine',
            'Asia/Dubai' => 'United Arab Emirates',
            'Europe/London' => 'United Kingdom',
            'America/Adak' => 'United States',
            'America/Anchorage' => 'United States',
            'America/Boise' => 'United States',
            'America/Chicago' => 'United States',
            'America/Denver' => 'United States',
            'America/Detroit' => 'United States',
            'America/Indiana/Indianapolis' => 'United States',
            'America/Indiana/Knox' => 'United States',
            'America/Indiana/Marengo' => 'United States',
            'America/Indiana/Petersburg' => 'United States',
            'America/Indiana/Tell_City' => 'United States',
            'America/Indiana/Vevay' => 'United States',
            'America/Indiana/Vincennes' => 'United States',
            'America/Indiana/Winamac' => 'United States',
            'America/Juneau' => 'United States',
            'America/Kentucky/Louisville' => 'United States',
            'America/Kentucky/Monticello' => 'United States',
            'America/Los_Angeles' => 'United States',
            'America/Menominee' => 'United States',
            'America/Metlakatla' => 'United States',
            'America/New_York' => 'United States',
            'America/Nome' => 'United States',
            'America/North_Dakota/Beulah' => 'United States',
            'America/North_Dakota/Center' => 'United States',
            'America/North_Dakota/New_Salem' => 'United States',
            'America/Phoenix' => 'United States',
            'America/Sitka' => 'United States',
            'America/Yakutat' => 'United States',
            'Pacific/Honolulu' => 'United States',
            'Pacific/Midway' => 'United States Minor Outlying Islands',
            'Pacific/Wake' => 'United States Minor Outlying Islands',
            'America/Montevideo' => 'Uruguay',
            'Asia/Samarkand' => 'Uzbekistan',
            'Asia/Tashkent' => 'Uzbekistan',
            'Pacific/Efate' => 'Vanuatu',
            'Bolivarian Republic of' => 'Venezuela',
            'Asia/Ho_Chi_Minh' => 'Viet Nam',
            'British' => 'Virgin Islands',
            'U.S.' => 'Virgin Islands',
            'Pacific/Wallis' => 'Wallis and Futuna',
            'Africa/El_Aaiun' => 'Western Sahara',
            'Asia/Aden' => 'Yemen',
            'Africa/Lusaka' => 'Zambia',
            'Africa/Harare' => 'Zimbabwe',
            'Europe/Mariehamn' => 'Åland Islands'
        );

Ref: https://timezonedb.com/time-zones

4

I have just had the same problem of making an easy to use time zone list. So I am using geoip (http://freegeoip.net) to get the user's country and then using:

$nearest_time_zones = DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, $country_code);

This is great because the list is generally very short. But in case the user wants to specify a different zone I append the entire list from DateTimeZone::listIdentifiers(). If you don't show all time zones, you're bound to have a user from a time zone that isn't listed.

The resulting drop down looks like this (of course it's a lot longer than this):

<optgroup label="Nearest">
<option value="blah/blah">(+5:00) Blah/Blah</option>
...
</optgroup>
<optgroup label="-11:00">
<option value="Pacific/Apia">(-11:00) Pacific/Apia</option>
<option value="Pacific/Midway">(-11:00) Pacific/Midway</option>
<option value="Pacific/Niue">(-11:00) Pacific/Niue</option>
<option value="Pacific/Pago_Pago">(-11:00) Pacific/Pago_Pago</option>
</optgroup>
<optgroup label="-10:00">
<option value="America/Adak">(-10:00) America/Adak</option>
<option value="Pacific/Fakaofo">(-10:00) Pacific/Fakaofo</option>
<option value="Pacific/Honolulu">(-10:00) Pacific/Honolulu</option>
<option value="Pacific/Johnston">(-10:00) Pacific/Johnston</option>
<option value="Pacific/Rarotonga">(-10:00) Pacific/Rarotonga</option>
<option value="Pacific/Tahiti">(-10:00) Pacific/Tahiti</option>
</optgroup>

This application is still in development and hasn't had user feedback yet so I can't say that this has been a successful approach. But I thought that the geoip approach was worth mentioning.

4

I used both lists from Jiew Meng and Tamás Pap, for each I checked PHP support of timezone identifier (PHP supports less than world knows), and made a composite list. For those Timezones which were in both lists and had support by PHP but had different identifiers I selected ones that are used in Geonames cities DB. Result is below:

$timezones = Array(
    '(GMT-12:00) International Date Line West' => 'Pacific/Kwajalein',
    '(GMT-11:00) Midway Island' => 'Pacific/Midway',
    '(GMT-11:00) Samoa' => 'Pacific/Apia',
    '(GMT-10:00) Hawaii' => 'Pacific/Honolulu',
    '(GMT-09:00) Alaska' => 'America/Anchorage',
    '(GMT-08:00) Pacific Time (US & Canada)' => 'America/Los_Angeles',
    '(GMT-08:00) Tijuana' => 'America/Tijuana',
    '(GMT-07:00) Arizona' => 'America/Phoenix',
    '(GMT-07:00) Mountain Time (US & Canada)' => 'America/Denver',
    '(GMT-07:00) Chihuahua' => 'America/Chihuahua',
    '(GMT-07:00) La Paz' => 'America/Chihuahua',
    '(GMT-07:00) Mazatlan' => 'America/Mazatlan',
    '(GMT-06:00) Central Time (US & Canada)' => 'America/Chicago',
    '(GMT-06:00) Central America' => 'America/Managua',
    '(GMT-06:00) Guadalajara' => 'America/Mexico_City',
    '(GMT-06:00) Mexico City' => 'America/Mexico_City',
    '(GMT-06:00) Monterrey' => 'America/Monterrey',
    '(GMT-06:00) Saskatchewan' => 'America/Regina',
    '(GMT-05:00) Eastern Time (US & Canada)' => 'America/New_York',
    '(GMT-05:00) Indiana (East)' => 'America/Indiana/Indianapolis',
    '(GMT-05:00) Bogota' => 'America/Bogota',
    '(GMT-05:00) Lima' => 'America/Lima',
    '(GMT-05:00) Quito' => 'America/Bogota',
    '(GMT-04:00) Atlantic Time (Canada)' => 'America/Halifax',
    '(GMT-04:00) Caracas' => 'America/Caracas',
    '(GMT-04:00) La Paz' => 'America/La_Paz',
    '(GMT-04:00) Santiago' => 'America/Santiago',
    '(GMT-03:30) Newfoundland' => 'America/St_Johns',
    '(GMT-03:00) Brasilia' => 'America/Sao_Paulo',
    '(GMT-03:00) Buenos Aires' => 'America/Argentina/Buenos_Aires',
    '(GMT-03:00) Georgetown' => 'America/Argentina/Buenos_Aires',
    '(GMT-03:00) Greenland' => 'America/Godthab',
    '(GMT-02:00) Mid-Atlantic' => 'America/Noronha',
    '(GMT-01:00) Azores' => 'Atlantic/Azores',
    '(GMT-01:00) Cape Verde Is.' => 'Atlantic/Cape_Verde',
    '(GMT) Casablanca' => 'Africa/Casablanca',
    '(GMT) Dublin' => 'Europe/London',
    '(GMT) Edinburgh' => 'Europe/London',
    '(GMT) Lisbon' => 'Europe/Lisbon',
    '(GMT) London' => 'Europe/London',
    '(GMT) Monrovia' => 'Africa/Monrovia',
    '(GMT+01:00) Amsterdam' => 'Europe/Amsterdam',
    '(GMT+01:00) Belgrade' => 'Europe/Belgrade',
    '(GMT+01:00) Berlin' => 'Europe/Berlin',
    '(GMT+01:00) Bern' => 'Europe/Berlin',
    '(GMT+01:00) Bratislava' => 'Europe/Bratislava',
    '(GMT+01:00) Brussels' => 'Europe/Brussels',
    '(GMT+01:00) Budapest' => 'Europe/Budapest',
    '(GMT+01:00) Copenhagen' => 'Europe/Copenhagen',
    '(GMT+01:00) Ljubljana' => 'Europe/Ljubljana',
    '(GMT+01:00) Madrid' => 'Europe/Madrid',
    '(GMT+01:00) Paris' => 'Europe/Paris',
    '(GMT+01:00) Prague' => 'Europe/Prague',
    '(GMT+01:00) Rome' => 'Europe/Rome',
    '(GMT+01:00) Sarajevo' => 'Europe/Sarajevo',
    '(GMT+01:00) Skopje' => 'Europe/Skopje',
    '(GMT+01:00) Stockholm' => 'Europe/Stockholm',
    '(GMT+01:00) Vienna' => 'Europe/Vienna',
    '(GMT+01:00) Warsaw' => 'Europe/Warsaw',
    '(GMT+01:00) West Central Africa' => 'Africa/Lagos',
    '(GMT+01:00) Zagreb' => 'Europe/Zagreb',
    '(GMT+02:00) Athens' => 'Europe/Athens',
    '(GMT+02:00) Bucharest' => 'Europe/Bucharest',
    '(GMT+02:00) Cairo' => 'Africa/Cairo',
    '(GMT+02:00) Harare' => 'Africa/Harare',
    '(GMT+02:00) Helsinki' => 'Europe/Helsinki',
    '(GMT+02:00) Istanbul' => 'Europe/Istanbul',
    '(GMT+02:00) Jerusalem' => 'Asia/Jerusalem',
    '(GMT+02:00) Kyev' => 'Europe/Kiev',
    '(GMT+02:00) Minsk' => 'Europe/Minsk',
    '(GMT+02:00) Pretoria' => 'Africa/Johannesburg',
    '(GMT+02:00) Riga' => 'Europe/Riga',
    '(GMT+02:00) Sofia' => 'Europe/Sofia',
    '(GMT+02:00) Tallinn' => 'Europe/Tallinn',
    '(GMT+02:00) Vilnius' => 'Europe/Vilnius',
    '(GMT+03:00) Baghdad' => 'Asia/Baghdad',
    '(GMT+03:00) Kuwait' => 'Asia/Kuwait',
    '(GMT+03:00) Moscow' => 'Europe/Moscow',
    '(GMT+03:00) Nairobi' => 'Africa/Nairobi',
    '(GMT+03:00) Riyadh' => 'Asia/Riyadh',
    '(GMT+03:00) St. Petersburg' => 'Europe/Moscow',
    '(GMT+03:00) Volgograd' => 'Europe/Volgograd',
    '(GMT+03:30) Tehran' => 'Asia/Tehran',
    '(GMT+04:00) Abu Dhabi' => 'Asia/Muscat',
    '(GMT+04:00) Baku' => 'Asia/Baku',
    '(GMT+04:00) Muscat' => 'Asia/Muscat',
    '(GMT+04:00) Tbilisi' => 'Asia/Tbilisi',
    '(GMT+04:00) Yerevan' => 'Asia/Yerevan',
    '(GMT+04:30) Kabul' => 'Asia/Kabul',
    '(GMT+05:00) Ekaterinburg' => 'Asia/Yekaterinburg',
    '(GMT+05:00) Islamabad' => 'Asia/Karachi',
    '(GMT+05:00) Karachi' => 'Asia/Karachi',
    '(GMT+05:00) Tashkent' => 'Asia/Tashkent',
    '(GMT+05:30) Chennai' => 'Asia/Kolkata',
    '(GMT+05:30) Kolkata' => 'Asia/Kolkata',
    '(GMT+05:30) Mumbai' => 'Asia/Kolkata',
    '(GMT+05:30) New Delhi' => 'Asia/Kolkata',
    '(GMT+05:45) Kathmandu' => 'Asia/Kathmandu',
    '(GMT+06:00) Almaty' => 'Asia/Almaty',
    '(GMT+06:00) Astana' => 'Asia/Dhaka',
    '(GMT+06:00) Dhaka' => 'Asia/Dhaka',
    '(GMT+06:00) Novosibirsk' => 'Asia/Novosibirsk',
    '(GMT+06:00) Sri Jayawardenepura' => 'Asia/Colombo',
    '(GMT+06:30) Rangoon' => 'Asia/Rangoon',
    '(GMT+07:00) Bangkok' => 'Asia/Bangkok',
    '(GMT+07:00) Hanoi' => 'Asia/Bangkok',
    '(GMT+07:00) Jakarta' => 'Asia/Jakarta',
    '(GMT+07:00) Krasnoyarsk' => 'Asia/Krasnoyarsk',
    '(GMT+08:00) Beijing' => 'Asia/Hong_Kong',
    '(GMT+08:00) Chongqing' => 'Asia/Chongqing',
    '(GMT+08:00) Hong Kong' => 'Asia/Hong_Kong',
    '(GMT+08:00) Irkutsk' => 'Asia/Irkutsk',
    '(GMT+08:00) Kuala Lumpur' => 'Asia/Kuala_Lumpur',
    '(GMT+08:00) Perth' => 'Australia/Perth',
    '(GMT+08:00) Singapore' => 'Asia/Singapore',
    '(GMT+08:00) Taipei' => 'Asia/Taipei',
    '(GMT+08:00) Ulaan Bataar' => 'Asia/Irkutsk',
    '(GMT+08:00) Urumqi' => 'Asia/Urumqi',
    '(GMT+09:00) Osaka' => 'Asia/Tokyo',
    '(GMT+09:00) Sapporo' => 'Asia/Tokyo',
    '(GMT+09:00) Seoul' => 'Asia/Seoul',
    '(GMT+09:00) Tokyo' => 'Asia/Tokyo',
    '(GMT+09:00) Yakutsk' => 'Asia/Yakutsk',
    '(GMT+09:30) Adelaide' => 'Australia/Adelaide',
    '(GMT+09:30) Darwin' => 'Australia/Darwin',
    '(GMT+10:00) Brisbane' => 'Australia/Brisbane',
    '(GMT+10:00) Canberra' => 'Australia/Sydney',
    '(GMT+10:00) Guam' => 'Pacific/Guam',
    '(GMT+10:00) Hobart' => 'Australia/Hobart',
    '(GMT+10:00) Melbourne' => 'Australia/Melbourne',
    '(GMT+10:00) Port Moresby' => 'Pacific/Port_Moresby',
    '(GMT+10:00) Sydney' => 'Australia/Sydney',
    '(GMT+10:00) Vladivostok' => 'Asia/Vladivostok',
    '(GMT+11:00) Magadan' => 'Asia/Magadan',
    '(GMT+11:00) New Caledonia' => 'Asia/Magadan',
    '(GMT+11:00) Solomon Is.' => 'Asia/Magadan',
    '(GMT+12:00) Auckland' => 'Pacific/Auckland',
    '(GMT+12:00) Fiji' => 'Pacific/Fiji',
    '(GMT+12:00) Kamchatka' => 'Asia/Kamchatka',
    '(GMT+12:00) Marshall Is.' => 'Pacific/Fiji',
    '(GMT+12:00) Wellington' => 'Pacific/Auckland',
    '(GMT+13:00) Nuku\'alofa' => 'Pacific/Tongatapu'
);
1
  • nice! this should be selected answer. btw, did you want to mention Eugene Manuilov instead of Jiew Meng?
    – T.Todua
    Commented Sep 18, 2017 at 17:22
3

try this:

<?php
/**
 * Timezones list with GMT offset
 *
 * @return array
 * @link http://stackoverflow.com/a/9328760
 */
function tz_list() {
  $zones_array = array();
  $timestamp = time();
  foreach(timezone_identifiers_list() as $key => $zone) {
    date_default_timezone_set($zone);
    $zones_array[$key]['zone'] = $zone;
    $zones_array[$key]['diff_from_GMT'] = 'UTC/GMT ' . date('P', $timestamp);
  }
  return $zones_array;
}
?>

<div style="margin-top: 20px;">
  <select style="font-family: 'Courier New', Courier, monospace; width: 450px;">
    <option value="0">Please, select timezone</option>
    <?php foreach(tz_list() as $t) { ?>
      <option value="<?php print $t['zone'] ?>">
        <?php print $t['diff_from_GMT'] . ' - ' . $t['zone'] ?>
      </option>
    <?php } ?>
  </select>
</div>

Source: http://www.pontikis.net/tip/?id=24

HTH

2

this method relies on your operating system, to make it so that it always works, just store the excisting timezones in an array/database, also you need to take into account the daylightsavingstime(s) wich can be quite some work

sourece http://en.wikipedia.org/wiki/Time_zone: PHP

The DateTime objects and related functions have been compiled into the PHP core since 5.2. This includes the ability to get and set the default script timezone, and DateTime is aware of its own timezone internally. PHP.net provides extensive documentation on this.[20] As noted there, the most current timezone database can be implemented via the PECL timezonedb.

so either make the db yourself, or use the PECL timezonedb

3
  • I don't really understand, is the offset given by PHP wrong? How is this affected by the OS? aren't I using values from PHP then just maths?
    – Jiew Meng
    Commented Jan 21, 2011 at 13:09
  • why downvote if you dont understand it, useing the PECL db is an option, and if you disagree with php's timezone settings, remember that daylight saving times arent too much of a standard thats why you can just better import the PECL db and have them deal with the problem instead of you having to deal with it Commented Feb 23, 2011 at 21:03
  • @jiewmeng sorry forgot to ref to you, prev message ;) Commented Feb 23, 2011 at 21:04
1

The below outputs the HTML <option>'s with all timezones specified in the $desiredRegions array.

function getAllTimeZones(){

    $zoneIdentifiers = timezone_identifiers_list();
    $zoneLocations = array();

    foreach ($zoneIdentifiers as $zoneIdentifier)
    {
        $zone = explode('/', $zoneIdentifier);
        $desiredRegions = array(
            'Africa', 'America', 'Antarctica', 'Arctic', 'Asia', 'Atlantic', 'Australia', 'Europe', 'Indian', 'Pacific'
        );
        if (in_array($zone[0], $desiredRegions))
        {
            if (isset($zone[1]) != '')
            {
                $area = str_replace('_', ' ', $zone[1]);
                if (!empty($zone[2]))
                {
                    $area = $area . ' (' . str_replace('_', ' ', $zone[2]) . ')';
                }
                $zoneLocations[$zone[0]][$zoneIdentifier] = $zone[0] . '/' .  $area;
            }
        }
    }

    $selectOptions = "";
    foreach($zoneLocations as $zoneRegion => $regionAreas)
    {
        foreach($regionAreas as $regionArea => $zoneLabel)
        {
            $currentTimeInZone = new DateTime("now", new DateTimeZone($regionArea));
            $currentTimeDiff = $currentTimeInZone->format('P');
            $selectOptions .= "<option value=\"$regionArea\">(GMT $currentTimeDiff) $zoneLabel</option>\n";
        }
    }
    return $selectOptions;
}

echo getAllTimeZones();

Output would look like:

<optgroup label="Africa">
<option value="Africa/Abidjan">(GMT +00:00) Africa/Abidjan</option>
<option value="Africa/Accra">(GMT +00:00) Africa/Accra</option>
<option value="Africa/Addis_Ababa">(GMT +03:00) Africa/Addis Ababa</option>
[...]
</optgroup>

Based on this gist.

0

I would like to leave here this idea:

/*----------TIME ZONE LIST---------*/
function TZList($data_type = false){
    $_all_timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::ALL);
    $TIMEZONE_LIST = array();
    foreach($_all_timezone_identifiers as $k => $v){
        $_tzone_group = explode("/", $_all_timezone_identifiers[$k])[0];

        $_tzone_new = new DateTimeZone($_all_timezone_identifiers[$k]);
        $_tzone_new_date = new DateTime("now", $_tzone_new);

        $tzone_arr = array(
                            'timezone' => $_all_timezone_identifiers[$k],
                            'timediff' => $_tzone_new_date->format('P'),
                            'timezone_offset' => $_tzone_new_date->format('Z')/60, //minutes
                            'text' => "(GMT" .$_tzone_new_date->format('P') .") " .$_all_timezone_identifiers[$k]
                            );

        //BY CONTINENT
        if($data_type === true) $TIMEZONE_LIST[$_tzone_group][] = $tzone_arr; else $TIMEZONE_LIST[] = $tzone_arr;
    }

    //BY TIMEZONE: "America/New_York"
    if(is_string($data_type)){
        $key = array_search($data_type, array_column($TIMEZONE_LIST, 'timezone'));
        $TIMEZONE_LIST = $key !== false ? $TIMEZONE_LIST[$key] : null;
    }

    return $TIMEZONE_LIST;
}
/*--------------------------------*/

Thank you.

-1
$america_timezones_list = array(
        '+00:00' => '(+00:00) Danmarkshavn',
        '-01:00' => '(-01:00) Scoresbysund',
        '-02:00' => '(-02:00) Noronha',
        '-03:00' => '(-03:00) Montevideo',
        '-03:00' => '(-03:00) Cayenne',
        '-03:00' => '(-03:00) Paramaribo',
        '-03:00' => '(-03:00) Miquelon',
        '-03:00' => '(-03:00) Araguaina',
        '-03:00' => '(-03:00) Santiago',
        '-03:00' => '(-03:00) Punta Arenas',
        '-03:00' => '(-03:00) Argentina/Buenos Aires',
        '-03:00' => '(-03:00) Argentina/Catamarca',
        '-03:00' => '(-03:00) Argentina/Mendoza',
        '-03:00' => '(-03:00) Argentina/San Luis',
        '-03:00' => '(-03:00) Argentina/San Juan',
        '-03:00' => '(-03:00) Argentina/La Rioja',
        '-03:00' => '(-03:00) Sao Paulo',
        '-03:00' => '(-03:00) Asuncion',
        '-03:00' => '(-03:00) Godthab',
        '-03:00' => '(-03:00) Bahia',
        '-03:00' => '(-03:00) Argentina/Rio Gallegos',
        '-03:00' => '(-03:00) Argentina/Jujuy',
        '-03:00' => '(-03:00) Argentina/Tucuman',
        '-03:00' => '(-03:00) Belem',
        '-03:00' => '(-03:00) Recife',
        '-03:00' => '(-03:00) Fortaleza',
        '-03:00' => '(-03:00) Santarem',
        '-03:00' => '(-03:00) Argentina/Cordoba',
        '-03:00' => '(-03:00) Maceio',
        '-03:00' => '(-03:00) Argentina/Salta',
        '-03:00' => '(-03:00) Argentina/Ushuaia',
        '-03:30' => '(-03:30) St Johns',
        '-04:00' => '(-04:00) St Barthelemy',
        '-04:00' => '(-04:00) Port of Spain',
        '-04:00' => '(-04:00) Santo Domingo',
        '-04:00' => '(-04:00) Anguilla',
        '-04:00' => '(-04:00) Tortola',
        '-04:00' => '(-04:00) Thule',
        '-04:00' => '(-04:00) Puerto Rico',
        '-04:00' => '(-04:00) Barbados',
        '-04:00' => '(-04:00) Porto Velho',
        '-04:00' => '(-04:00) Moncton',
        '-04:00' => '(-04:00) Martinique',
        '-04:00' => '(-04:00) La Paz',
        '-04:00' => '(-04:00) Cuiaba',
        '-04:00' => '(-04:00) Antigua',
        '-04:00' => '(-04:00) St Vincent',
        '-04:00' => '(-04:00) Montserrat',
        '-04:00' => '(-04:00) Boa Vista',
        '-04:00' => '(-04:00) Marigot',
        '-04:00' => '(-04:00) Manaus',
        '-04:00' => '(-04:00) Kralendijk',
        '-04:00' => '(-04:00) Goose Bay',
        '-04:00' => '(-04:00) Dominica',
        '-04:00' => '(-04:00) Campo Grande',
        '-04:00' => '(-04:00) Lower Princes',
        '-04:00' => '(-04:00) St Thomas',
        '-04:00' => '(-04:00) Halifax',
        '-04:00' => '(-04:00) St Lucia',
        '-04:00' => '(-04:00) Caracas',
        '-04:00' => '(-04:00) Guyana',
        '-04:00' => '(-04:00) St Kitts',
        '-04:00' => '(-04:00) Curacao',
        '-04:00' => '(-04:00) Aruba',
        '-04:00' => '(-04:00) Blanc-Sablon',
        '-04:00' => '(-04:00) Glace Bay',
        '-04:00' => '(-04:00) Grenada',
        '-04:00' => '(-04:00) Guadeloupe',
        '-05:00' => '(-05:00) Indiana/Marengo',
        '-05:00' => '(-05:00) Indiana/Indianapolis',
        '-05:00' => '(-05:00) Havana',
        '-05:00' => '(-05:00) New York',
        '-05:00' => '(-05:00) Indiana/Vincennes',
        '-05:00' => '(-05:00) Jamaica',
        '-05:00' => '(-05:00) Port-au-Prince',
        '-05:00' => '(-05:00) Panama',
        '-05:00' => '(-05:00) Nassau',
        '-05:00' => '(-05:00) Thunder Bay',
        '-05:00' => '(-05:00) Kentucky/Monticello',
        '-05:00' => '(-05:00) Kentucky/Louisville',
        '-05:00' => '(-05:00) Lima',
        '-05:00' => '(-05:00) Atikokan',
        '-05:00' => '(-05:00) Cancun',
        '-05:00' => '(-05:00) Cayman',
        '-05:00' => '(-05:00) Bogota',
        '-05:00' => '(-05:00) Iqaluit',
        '-05:00' => '(-05:00) Nipigon',
        '-05:00' => '(-05:00) Pangnirtung',
        '-05:00' => '(-05:00) Indiana/Vevay',
        '-05:00' => '(-05:00) Indiana/Winamac',
        '-05:00' => '(-05:00) Indiana/Petersburg',
        '-05:00' => '(-05:00) Guayaquil',
        '-05:00' => '(-05:00) Grand Turk',
        '-05:00' => '(-05:00) Detroit',
        '-05:00' => '(-05:00) Eirunepe',
        '-05:00' => '(-05:00) Rio Branco',
        '-05:00' => '(-05:00) Toronto',
        '-06:00' => '(-06:00) Belize',
        '-06:00' => '(-06:00) Indiana/Tell City',
        '-06:00' => '(-06:00) Chicago',
        '-06:00' => '(-06:00) Merida',
        '-06:00' => '(-06:00) Managua',
        '-06:00' => '(-06:00) Menominee',
        '-06:00' => '(-06:00) Rankin Inlet',
        '-06:00' => '(-06:00) Tegucigalpa',
        '-06:00' => '(-06:00) Mexico City',
        '-06:00' => '(-06:00) North Dakota/Center',
        '-06:00' => '(-06:00) Rainy River',
        '-06:00' => '(-06:00) Resolute',
        '-06:00' => '(-06:00) Indiana/Knox',
        '-06:00' => '(-06:00) El Salvador',
        '-06:00' => '(-06:00) Costa Rica',
        '-06:00' => '(-06:00) Matamoros',
        '-06:00' => '(-06:00) Winnipeg',
        '-06:00' => '(-06:00) Bahia Banderas',
        '-06:00' => '(-06:00) Regina',
        '-06:00' => '(-06:00) North Dakota/Beulah',
        '-06:00' => '(-06:00) Swift Current',
        '-06:00' => '(-06:00) Guatemala',
        '-06:00' => '(-06:00) North Dakota/New Salem',
        '-06:00' => '(-06:00) Monterrey',
        '-07:00' => '(-07:00) Mazatlan',
        '-07:00' => '(-07:00) Ojinaga',
        '-07:00' => '(-07:00) Chihuahua',
        '-07:00' => '(-07:00) Denver',
        '-07:00' => '(-07:00) Phoenix',
        '-07:00' => '(-07:00) Hermosillo',
        '-07:00' => '(-07:00) Creston',
        '-07:00' => '(-07:00) Yellowknife',
        '-07:00' => '(-07:00) Inuvik',
        '-07:00' => '(-07:00) Edmonton',
        '-07:00' => '(-07:00) Dawson Creek',
        '-07:00' => '(-07:00) Cambridge Bay',
        '-07:00' => '(-07:00) Fort Nelson',
        '-07:00' => '(-07:00) Boise',
        '-08:00' => '(-08:00) Los Angeles',
        '-08:00' => '(-08:00) Vancouver',
        '-08:00' => '(-08:00) Tijuana',
        '-08:00' => '(-08:00) Dawson',
        '-08:00' => '(-08:00) Whitehorse',
        '-09:00' => '(-09:00) Yakutat',
        '-09:00' => '(-09:00) Juneau',
        '-09:00' => '(-09:00) Nome',
        '-09:00' => '(-09:00) Anchorage',
        '-09:00' => '(-09:00) Sitka',
        '-09:00' => '(-09:00) Metlakatla',
        '-10:00' => '(-10:00) Adak'
    );

Not the answer you're looking for? Browse other questions tagged or ask your own question.