PHP Function Reference

PHP DateTimeZone - listIdentifiers() Method



The PHP DateTimeZone::listIdentifiers() method returns a numerically indexed array containing all defined timezone identifiers. The timezone_identifiers_list() function is an alias of this method.

Syntax

//Object-oriented style
public DateTimeZone::listIdentifiers(timezoneGroup, countryCode)

//Procedural style
timezone_identifiers_list(timezoneGroup, countryCode)

Parameters

timezoneGroup Optional. Specify one of the DateTimeZone class constants (or a combination). Default is DateTimeZone::ALL.
countryCode Optional. Specify a two-letter ISO 3166-1 compatible country code. This option is only used when timezoneGroup is set to DateTimeZone::PER_COUNTRY.

Return Value

Returns the array of timezone identifiers.

Example: using both styles

The example below shows the usage of DateTimeZone::listIdentifiers() method.

<?php
  //getting the timezone identifiers using Object-oriented
  //style and displaying few identifiers
  $retval1 = DateTimeZone::listIdentifiers();
  for ($i=0; $i < 10; $i++) {
    echo "$retval1[$i]\n";
  }

  echo "-------------------\n";

  //getting the timezone identifiers using Procedural
  //style and displaying few identifiers
  $retval2 = timezone_identifiers_list();
  for ($i=100; $i < 110; $i++) {
    echo "$retval2[$i]\n";
  } 
?>

The output of the above code will be:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul
Africa/Bissau
Africa/Blantyre
-------------------
America/Eirunepe
America/El_Salvador
America/Fort_Nelson
America/Fortaleza
America/Glace_Bay
America/Goose_Bay
America/Grand_Turk
America/Grenada
America/Guadeloupe
America/Guatemala

Example: using timezoneGroup and countryCode parameters

The timezoneGroup parameter can be specified as one of the DateTimeZone class constants and countryCode can be specified as two-letter ISO 3166-1 compatible country code. Consider the example below:

<?php
  //getting the timezone identifiers for Europe 
  //timezoneGroup and displaying few identifiers
  $retval = DateTimeZone::listIdentifiers(128);
  for ($i=0; $i < 10; $i++) {
    echo "$retval[$i]\n";
  }

  echo "-------------------\n";

  //getting the timezone identifiers for USA
  print_r(DateTimeZone::listIdentifiers(4096, "US"));
?>

The output of the above code will be:

Europe/Amsterdam
Europe/Andorra
Europe/Astrakhan
Europe/Athens
Europe/Belgrade
Europe/Berlin
Europe/Bratislava
Europe/Brussels
Europe/Bucharest
Europe/Budapest
-------------------
Array
(
    [0] => America/Adak
    [1] => America/Anchorage
    [2] => America/Boise
    [3] => America/Chicago
    [4] => America/Denver
    [5] => America/Detroit
    [6] => America/Indiana/Indianapolis
    [7] => America/Indiana/Knox
    [8] => America/Indiana/Marengo
    [9] => America/Indiana/Petersburg
    [10] => America/Indiana/Tell_City
    [11] => America/Indiana/Vevay
    [12] => America/Indiana/Vincennes
    [13] => America/Indiana/Winamac
    [14] => America/Juneau
    [15] => America/Kentucky/Louisville
    [16] => America/Kentucky/Monticello
    [17] => America/Los_Angeles
    [18] => America/Menominee
    [19] => America/Metlakatla
    [20] => America/New_York
    [21] => America/Nome
    [22] => America/North_Dakota/Beulah
    [23] => America/North_Dakota/Center
    [24] => America/North_Dakota/New_Salem
    [25] => America/Phoenix
    [26] => America/Sitka
    [27] => America/Yakutat
    [28] => Pacific/Honolulu
)

❮ PHP Date and Time Reference