title: Generating a drop down list of timezones with PHP
body: <p>Most sites need some way to show the dates on the site in the users preferred timezone. Below are <a href="http://www.phpbb.com" rel="noreferrer">two lists</a> that <a href="http://www.aviblock.com/blog/2009/03/12/presenting-a-list-of-timezones-to-the-user/" rel="noreferrer">I found and</a> then one method <a href="http://us.php.net/manual/en/function.date-default-timezone-set.php#84459" rel="noreferrer">using the built in PHP DateTime</a> class in PHP 5. </p>
  
  <p>I need help knowing which of these would be the best to attempt to use when trying to get the UTC offset from the user on register.</p>
  
  <p>One:</p>
  
  <pre><code>&lt;option value="-12"&gt;[UTC - 12] Baker Island Time&lt;/option&gt;
  &lt;option value="-11"&gt;[UTC - 11] Niue Time, Samoa Standard Time&lt;/option&gt;
  &lt;option value="-10"&gt;[UTC - 10] Hawaii-Aleutian Standard Time, Cook Island Time&lt;/option&gt;
  &lt;option value="-9.5"&gt;[UTC - 9:30] Marquesas Islands Time&lt;/option&gt;
  &lt;option value="-9"&gt;[UTC - 9] Alaska Standard Time, Gambier Island Time&lt;/option&gt;
  &lt;option value="-8"&gt;[UTC - 8] Pacific Standard Time&lt;/option&gt;
  &lt;option value="-7"&gt;[UTC - 7] Mountain Standard Time&lt;/option&gt;
  &lt;option value="-6"&gt;[UTC - 6] Central Standard Time&lt;/option&gt;
  &lt;option value="-5"&gt;[UTC - 5] Eastern Standard Time&lt;/option&gt;
  &lt;option value="-4.5"&gt;[UTC - 4:30] Venezuelan Standard Time&lt;/option&gt;
  &lt;option value="-4"&gt;[UTC - 4] Atlantic Standard Time&lt;/option&gt;
  &lt;option value="-3.5"&gt;[UTC - 3:30] Newfoundland Standard Time&lt;/option&gt;
  &lt;option value="-3"&gt;[UTC - 3] Amazon Standard Time, Central Greenland Time&lt;/option&gt;
  &lt;option value="-2"&gt;[UTC - 2] Fernando de Noronha Time, South Georgia &amp;amp; the South Sandwich Islands Time&lt;/option&gt;
  &lt;option value="-1"&gt;[UTC - 1] Azores Standard Time, Cape Verde Time, Eastern Greenland Time&lt;/option&gt;
  &lt;option value="0" selected="selected"&gt;[UTC] Western European Time, Greenwich Mean Time&lt;/option&gt;
  &lt;option value="1"&gt;[UTC + 1] Central European Time, West African Time&lt;/option&gt;
  &lt;option value="2"&gt;[UTC + 2] Eastern European Time, Central African Time&lt;/option&gt;
  &lt;option value="3"&gt;[UTC + 3] Moscow Standard Time, Eastern African Time&lt;/option&gt;
  &lt;option value="3.5"&gt;[UTC + 3:30] Iran Standard Time&lt;/option&gt;
  &lt;option value="4"&gt;[UTC + 4] Gulf Standard Time, Samara Standard Time&lt;/option&gt;
  &lt;option value="4.5"&gt;[UTC + 4:30] Afghanistan Time&lt;/option&gt;
  &lt;option value="5"&gt;[UTC + 5] Pakistan Standard Time, Yekaterinburg Standard Time&lt;/option&gt;
  &lt;option value="5.5"&gt;[UTC + 5:30] Indian Standard Time, Sri Lanka Time&lt;/option&gt;
  &lt;option value="5.75"&gt;[UTC + 5:45] Nepal Time&lt;/option&gt;
  &lt;option value="6"&gt;[UTC + 6] Bangladesh Time, Bhutan Time, Novosibirsk Standard Time&lt;/option&gt;
  &lt;option value="6.5"&gt;[UTC + 6:30] Cocos Islands Time, Myanmar Time&lt;/option&gt;
  &lt;option value="7"&gt;[UTC + 7] Indochina Time, Krasnoyarsk Standard Time&lt;/option&gt;
  &lt;option value="8"&gt;[UTC + 8] Chinese Standard Time, Australian Western Standard Time, Irkutsk Standard Time&lt;/option&gt;
  &lt;option value="8.75"&gt;[UTC + 8:45] Southeastern Western Australia Standard Time&lt;/option&gt;
  &lt;option value="9"&gt;[UTC + 9] Japan Standard Time, Korea Standard Time, Chita Standard Time&lt;/option&gt;
  &lt;option value="9.5"&gt;[UTC + 9:30] Australian Central Standard Time&lt;/option&gt;
  &lt;option value="10"&gt;[UTC + 10] Australian Eastern Standard Time, Vladivostok Standard Time&lt;/option&gt;
  &lt;option value="10.5"&gt;[UTC + 10:30] Lord Howe Standard Time&lt;/option&gt;
  &lt;option value="11"&gt;[UTC + 11] Solomon Island Time, Magadan Standard Time&lt;/option&gt;
  &lt;option value="11.5"&gt;[UTC + 11:30] Norfolk Island Time&lt;/option&gt;
  &lt;option value="12"&gt;[UTC + 12] New Zealand Time, Fiji Time, Kamchatka Standard Time&lt;/option&gt;
  &lt;option value="12.75"&gt;[UTC + 12:45] Chatham Islands Time&lt;/option&gt;
  &lt;option value="13"&gt;[UTC + 13] Tonga Time, Phoenix Islands Time&lt;/option&gt;
  &lt;option value="14"&gt;[UTC + 14] Line Island Time&lt;/option&gt;
  </code></pre>
  
  <p>Or using PHP friendly values:</p>
  
  <pre><code>&lt;option value="Pacific/Midway"&gt;(GMT-11:00) Midway Island, Samoa&lt;/option&gt;
  &lt;option value="America/Adak"&gt;(GMT-10:00) Hawaii-Aleutian&lt;/option&gt;
  &lt;option value="Etc/GMT+10"&gt;(GMT-10:00) Hawaii&lt;/option&gt;
  &lt;option value="Pacific/Marquesas"&gt;(GMT-09:30) Marquesas Islands&lt;/option&gt;
  &lt;option value="Pacific/Gambier"&gt;(GMT-09:00) Gambier Islands&lt;/option&gt;
  &lt;option value="America/Anchorage"&gt;(GMT-09:00) Alaska&lt;/option&gt;
  &lt;option value="America/Ensenada"&gt;(GMT-08:00) Tijuana, Baja California&lt;/option&gt;
  &lt;option value="Etc/GMT+8"&gt;(GMT-08:00) Pitcairn Islands&lt;/option&gt;
  &lt;option value="America/Los_Angeles"&gt;(GMT-08:00) Pacific Time (US &amp; Canada)&lt;/option&gt;
  &lt;option value="America/Denver"&gt;(GMT-07:00) Mountain Time (US &amp; Canada)&lt;/option&gt;
  &lt;option value="America/Chihuahua"&gt;(GMT-07:00) Chihuahua, La Paz, Mazatlan&lt;/option&gt;
  &lt;option value="America/Dawson_Creek"&gt;(GMT-07:00) Arizona&lt;/option&gt;
  &lt;option value="America/Belize"&gt;(GMT-06:00) Saskatchewan, Central America&lt;/option&gt;
  &lt;option value="America/Cancun"&gt;(GMT-06:00) Guadalajara, Mexico City, Monterrey&lt;/option&gt;
  &lt;option value="Chile/EasterIsland"&gt;(GMT-06:00) Easter Island&lt;/option&gt;
  &lt;option value="America/Chicago"&gt;(GMT-06:00) Central Time (US &amp; Canada)&lt;/option&gt;
  &lt;option value="America/New_York"&gt;(GMT-05:00) Eastern Time (US &amp; Canada)&lt;/option&gt;
  &lt;option value="America/Havana"&gt;(GMT-05:00) Cuba&lt;/option&gt;
  &lt;option value="America/Bogota"&gt;(GMT-05:00) Bogota, Lima, Quito, Rio Branco&lt;/option&gt;
  &lt;option value="America/Caracas"&gt;(GMT-04:30) Caracas&lt;/option&gt;
  &lt;option value="America/Santiago"&gt;(GMT-04:00) Santiago&lt;/option&gt;
  &lt;option value="America/La_Paz"&gt;(GMT-04:00) La Paz&lt;/option&gt;
  &lt;option value="Atlantic/Stanley"&gt;(GMT-04:00) Faukland Islands&lt;/option&gt;
  &lt;option value="America/Campo_Grande"&gt;(GMT-04:00) Brazil&lt;/option&gt;
  &lt;option value="America/Goose_Bay"&gt;(GMT-04:00) Atlantic Time (Goose Bay)&lt;/option&gt;
  &lt;option value="America/Glace_Bay"&gt;(GMT-04:00) Atlantic Time (Canada)&lt;/option&gt;
  &lt;option value="America/St_Johns"&gt;(GMT-03:30) Newfoundland&lt;/option&gt;
  &lt;option value="America/Araguaina"&gt;(GMT-03:00) UTC-3&lt;/option&gt;
  &lt;option value="America/Montevideo"&gt;(GMT-03:00) Montevideo&lt;/option&gt;
  &lt;option value="America/Miquelon"&gt;(GMT-03:00) Miquelon, St. Pierre&lt;/option&gt;
  &lt;option value="America/Godthab"&gt;(GMT-03:00) Greenland&lt;/option&gt;
  &lt;option value="America/Argentina/Buenos_Aires"&gt;(GMT-03:00) Buenos Aires&lt;/option&gt;
  &lt;option value="America/Sao_Paulo"&gt;(GMT-03:00) Brasilia&lt;/option&gt;
  &lt;option value="America/Noronha"&gt;(GMT-02:00) Mid-Atlantic&lt;/option&gt;
  &lt;option value="Atlantic/Cape_Verde"&gt;(GMT-01:00) Cape Verde Is.&lt;/option&gt;
  &lt;option value="Atlantic/Azores"&gt;(GMT-01:00) Azores&lt;/option&gt;
  &lt;option value="Europe/Belfast"&gt;(GMT) Greenwich Mean Time : Belfast&lt;/option&gt;
  &lt;option value="Europe/Dublin"&gt;(GMT) Greenwich Mean Time : Dublin&lt;/option&gt;
  &lt;option value="Europe/Lisbon"&gt;(GMT) Greenwich Mean Time : Lisbon&lt;/option&gt;
  &lt;option value="Europe/London"&gt;(GMT) Greenwich Mean Time : London&lt;/option&gt;
  &lt;option value="Africa/Abidjan"&gt;(GMT) Monrovia, Reykjavik&lt;/option&gt;
  &lt;option value="Europe/Amsterdam"&gt;(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna&lt;/option&gt;
  &lt;option value="Europe/Belgrade"&gt;(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague&lt;/option&gt;
  &lt;option value="Europe/Brussels"&gt;(GMT+01:00) Brussels, Copenhagen, Madrid, Paris&lt;/option&gt;
  &lt;option value="Africa/Algiers"&gt;(GMT+01:00) West Central Africa&lt;/option&gt;
  &lt;option value="Africa/Windhoek"&gt;(GMT+01:00) Windhoek&lt;/option&gt;
  &lt;option value="Asia/Beirut"&gt;(GMT+02:00) Beirut&lt;/option&gt;
  &lt;option value="Africa/Cairo"&gt;(GMT+02:00) Cairo&lt;/option&gt;
  &lt;option value="Asia/Gaza"&gt;(GMT+02:00) Gaza&lt;/option&gt;
  &lt;option value="Africa/Blantyre"&gt;(GMT+02:00) Harare, Pretoria&lt;/option&gt;
  &lt;option value="Asia/Jerusalem"&gt;(GMT+02:00) Jerusalem&lt;/option&gt;
  &lt;option value="Europe/Minsk"&gt;(GMT+02:00) Minsk&lt;/option&gt;
  &lt;option value="Asia/Damascus"&gt;(GMT+02:00) Syria&lt;/option&gt;
  &lt;option value="Europe/Moscow"&gt;(GMT+03:00) Moscow, St. Petersburg, Volgograd&lt;/option&gt;
  &lt;option value="Africa/Addis_Ababa"&gt;(GMT+03:00) Nairobi&lt;/option&gt;
  &lt;option value="Asia/Tehran"&gt;(GMT+03:30) Tehran&lt;/option&gt;
  &lt;option value="Asia/Dubai"&gt;(GMT+04:00) Abu Dhabi, Muscat&lt;/option&gt;
  &lt;option value="Asia/Yerevan"&gt;(GMT+04:00) Yerevan&lt;/option&gt;
  &lt;option value="Asia/Kabul"&gt;(GMT+04:30) Kabul&lt;/option&gt;
  &lt;option value="Asia/Yekaterinburg"&gt;(GMT+05:00) Ekaterinburg&lt;/option&gt;
  &lt;option value="Asia/Tashkent"&gt;(GMT+05:00) Tashkent&lt;/option&gt;
  &lt;option value="Asia/Kolkata"&gt;(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi&lt;/option&gt;
  &lt;option value="Asia/Katmandu"&gt;(GMT+05:45) Kathmandu&lt;/option&gt;
  &lt;option value="Asia/Dhaka"&gt;(GMT+06:00) Astana, Dhaka&lt;/option&gt;
  &lt;option value="Asia/Novosibirsk"&gt;(GMT+06:00) Novosibirsk&lt;/option&gt;
  &lt;option value="Asia/Rangoon"&gt;(GMT+06:30) Yangon (Rangoon)&lt;/option&gt;
  &lt;option value="Asia/Bangkok"&gt;(GMT+07:00) Bangkok, Hanoi, Jakarta&lt;/option&gt;
  &lt;option value="Asia/Krasnoyarsk"&gt;(GMT+07:00) Krasnoyarsk&lt;/option&gt;
  &lt;option value="Asia/Hong_Kong"&gt;(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi&lt;/option&gt;
  &lt;option value="Asia/Irkutsk"&gt;(GMT+08:00) Irkutsk, Ulaan Bataar&lt;/option&gt;
  &lt;option value="Australia/Perth"&gt;(GMT+08:00) Perth&lt;/option&gt;
  &lt;option value="Australia/Eucla"&gt;(GMT+08:45) Eucla&lt;/option&gt;
  &lt;option value="Asia/Tokyo"&gt;(GMT+09:00) Osaka, Sapporo, Tokyo&lt;/option&gt;
  &lt;option value="Asia/Seoul"&gt;(GMT+09:00) Seoul&lt;/option&gt;
  &lt;option value="Asia/Yakutsk"&gt;(GMT+09:00) Yakutsk&lt;/option&gt;
  &lt;option value="Australia/Adelaide"&gt;(GMT+09:30) Adelaide&lt;/option&gt;
  &lt;option value="Australia/Darwin"&gt;(GMT+09:30) Darwin&lt;/option&gt;
  &lt;option value="Australia/Brisbane"&gt;(GMT+10:00) Brisbane&lt;/option&gt;
  &lt;option value="Australia/Hobart"&gt;(GMT+10:00) Hobart&lt;/option&gt;
  &lt;option value="Asia/Vladivostok"&gt;(GMT+10:00) Vladivostok&lt;/option&gt;
  &lt;option value="Australia/Lord_Howe"&gt;(GMT+10:30) Lord Howe Island&lt;/option&gt;
  &lt;option value="Etc/GMT-11"&gt;(GMT+11:00) Solomon Is., New Caledonia&lt;/option&gt;
  &lt;option value="Asia/Magadan"&gt;(GMT+11:00) Magadan&lt;/option&gt;
  &lt;option value="Pacific/Norfolk"&gt;(GMT+11:30) Norfolk Island&lt;/option&gt;
  &lt;option value="Asia/Anadyr"&gt;(GMT+12:00) Anadyr, Kamchatka&lt;/option&gt;
  &lt;option value="Pacific/Auckland"&gt;(GMT+12:00) Auckland, Wellington&lt;/option&gt;
  &lt;option value="Etc/GMT-12"&gt;(GMT+12:00) Fiji, Kamchatka, Marshall Is.&lt;/option&gt;
  &lt;option value="Pacific/Chatham"&gt;(GMT+12:45) Chatham Islands&lt;/option&gt;
  &lt;option value="Pacific/Tongatapu"&gt;(GMT+13:00) Nuku'alofa&lt;/option&gt;
  &lt;option value="Pacific/Kiritimati"&gt;(GMT+14:00) Kiritimati&lt;/option&gt;
  </code></pre>
  
  <p>Or just using PHP itself:</p>
  
  <pre><code>$timezones = DateTimeZone::listAbbreviations();
  
  $cities = array();
  foreach( $timezones as $key =&gt; $zones )
  {
      foreach( $zones as $id =&gt; $zone )
      {
          /**
           * Only get timezones explicitely not part of "Others".
           * @see http://www.php.net/manual/en/timezones.others.php
           */
          if ( preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $zone['timezone_id'] ) 
              &amp;&amp; $zone['timezone_id']) {
              $cities[$zone['timezone_id']][] = $key;
          }
      }
  }
  
  // For each city, have a comma separated list of all possible timezones for that city.
  foreach( $cities as $key =&gt; $value )
      $cities[$key] = join( ', ', $value);
  
  // Only keep one city (the first and also most important) for each set of possibilities. 
  $cities = array_unique( $cities );
  
  // Sort by area/city name.
  ksort( $cities );
  </code></pre>
  
  <p>It seems like the last one would be the safest as it would grow with the PHP release being used. You could also flip that array around when needed to tie timezones to city names.</p>