PHP | timezone_identifiers_list() Function

The timezone_identifiers_list() function is an inbuilt function in PHP which is used to return an indexed array containing all the timezone identifiers. The datetimezone object is sent as a parameter to the timezone_identifiers_list() function and it returns an indexed array on success or False on failure.

Syntax:

array timezone_identifiers_list( $datetimezone, $country )

Parameters: This function accepts two parameter as mentioned above and described below:



  • $datetimezone: It is an optional parameter which specifies the DateTimeZone class constant.
  • country: It is also an optional parameter which specifies a two-letter ISO 3166-1 compatible country code.

Return Value: This function returns an indexed array on success or False on failure.

Exceptions: The timezone_identifiers_list() function is an alias of DateTimeZone::listIdentifiers() function.

Below programs illustrate the timezone_identifiers_list() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Displaying all the timezone identifiers of Antarctica
echo ("All the timezones available in this timezone are ");
print_r(timezone_identifiers_list(4));
?>

chevron_right


Output:

All the timezones available in this timezone are Array
(
    [0] => Antarctica/Casey
    [1] => Antarctica/Davis
    [2] => Antarctica/DumontDUrville
    [3] => Antarctica/Macquarie
    [4] => Antarctica/Mawson
    [5] => Antarctica/McMurdo
    [6] => Antarctica/Palmer
    [7] => Antarctica/Rothera
    [8] => Antarctica/Syowa
    [9] => Antarctica/Troll
    [10] => Antarctica/Vostok
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Displaying the timezone identifiers of Africa
$timezone_identifiers = DateTimeZone::listIdentifiers();
for ($i = 0; $i < 8; $i++) 
{
    echo "$timezone_identifiers[$i]\n";
}
?>

chevron_right


Output:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Bamako
Africa/Bangui
Africa/Banjul

Related Articles:

Reference: http://php.net/manual/en/function.timezone-identifiers-list.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.