Signature
timezone_identifiers_list(int $timezoneGroup = DateTimeZone::ALL, ?string $countryCode = null): arrayPurpose
timezone_identifiers_list() returns the time zone identifiers that PHP knows about, such as UTC, Europe/Paris or Asia/Tokyo. You typically use it to build a time zone dropdown, to check that a stored identifier is valid, or to narrow choices to one region or country.
The function is a procedural alias of DateTimeZone::listIdentifiers(). Both behave the same way, so pick the style that fits the rest of your code.
Signature
Parameters and defaults
$timezoneGroupselects which identifiers to return. The default isDateTimeZone::ALL. The class constants include the regional groupsAFRICA,AMERICA,ANTARCTICA,ARCTIC,ASIA,ATLANTIC,AUSTRALIA,EUROPE,INDIANandPACIFIC. They also includeUTC,ALL,ALL_WITH_BCandPER_COUNTRY. Regional groups are bit flags, so they can be combined with|.$countryCodeis only meaningful withDateTimeZone::PER_COUNTRY. It is a two-letter ISO 3166-1 country code such asJPorNZ. With any other group it is ignored. The default isnull.
Return value and failure cases
The function returns a list array of strings. Each element is an identifier. An unrecognised group value gives no useful identifiers, so stick to the class constants.
If you use DateTimeZone::PER_COUNTRY with a missing or malformed country code, PHP 8 raises a ValueError instead of quietly returning something. A well-formed code that has no zones yields an empty array.
The contents of the list depend on the time zone database bundled with your PHP build. Zones may be added or renamed between releases, so avoid hard-coding the total number of identifiers.
Example 1: the UTC group
The UTC group is the smallest possible filter. It contains just the one identifier.
$zones = timezone_identifiers_list(DateTimeZone::UTC);
echo json_encode($zones, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";["UTC"]
Example 2: zones for one country
Combine PER_COUNTRY with a country code to list the zones used there. Japan uses a single zone.
$zones = timezone_identifiers_list(DateTimeZone::PER_COUNTRY, 'JP');
echo json_encode($zones, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";["Asia/Tokyo"]
Example 3: validating a submitted identifier
A common use is checking user input against the known list. Use strict comparison, and remember that matching is case-sensitive.
function isListedZone(string $id): bool
{
return in_array($id, timezone_identifiers_list(), true);
}
$result = [
'Europe/Paris' => isListedZone('Europe/Paris'),
'europe/paris' => isListedZone('europe/paris'),
'Mars/Base' => isListedZone('Mars/Base'),
];
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";{"Europe/Paris":true,"europe/paris":false,"Mars/Base":false}
Edge cases
- Case sensitivity. The list contains canonical spellings.
europe/parisis not in the array, even though some PHP date APIs may be more forgiving when constructing a zone. - Backward-compatible names.
DateTimeZone::ALLdoes not include legacy aliases. UseDateTimeZone::ALL_WITH_BCif you must recognise those older names. - Country code is ignored without
PER_COUNTRY. Passing'JP'together withDateTimeZone::ASIAstill returns every Asian zone. - Abbreviations are not identifiers. Values such as
ESTorCESTare abbreviations. Identifiers use theArea/Locationform, except for entries likeUTC. - Order and size. Do not depend on the number of entries or on a specific position. Look values up instead.
Common mistakes
- Passing a country code without
DateTimeZone::PER_COUNTRYand expecting filtering. - Using loose
in_array()without the strict flag. It works on strings here, but strict comparison is a safer habit. - Hard-coding a count of zones in tests. The count depends on the bundled database.
- Treating the list as a list of offsets. It has names only. Create a
DateTimeZoneobject and ask for offsets at a specific moment if you need them. - Calling the function repeatedly inside a loop. Store the result in a variable or a
array_flip()lookup table when you validate many values.
Related functions
DateTimeZone::listIdentifiers(), the method this function aliasestimezone_abbreviations_list()for abbreviation datatimezone_open()andDateTimeZone::__construct()for creating a zone objectdate_default_timezone_set()for choosing the default zone
Recap
timezone_identifiers_list() returns an array of time zone identifier strings, optionally filtered by group or by country with PER_COUNTRY. It is an alias of DateTimeZone::listIdentifiers(). Treat its contents as data from the bundled database, compare names exactly, and never assume a fixed size.
Tested examples
$zones = timezone_identifiers_list(DateTimeZone::UTC);
echo json_encode($zones, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
["UTC"]
$zones = timezone_identifiers_list(DateTimeZone::PER_COUNTRY, 'JP');
echo json_encode($zones, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
["Asia/Tokyo"]
function isListedZone(string $id): bool
{
return in_array($id, timezone_identifiers_list(), true);
}
$result = [
'Europe/Paris' => isListedZone('Europe/Paris'),
'europe/paris' => isListedZone('europe/paris'),
'Mars/Base' => isListedZone('Mars/Base'),
];
echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), "\n";
{"Europe/Paris":true,"europe/paris":false,"Mars/Base":false}