How to generate a drop down list of timezone using PHP ? Last Updated : 11 Oct, 2019 Comments Improve Suggest changes Like Article Like Report The timezone_identifiers_list() function is used to generate a dropdown list of timezone with PHP. This function 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. This function is an alias of DateTimeZone::listIdentifiers() function. The timezone_identifiers_list() function uses its timezone constants and country to display a list of timezone independently. Such that the possible values for timezone constants are: 1 = AFRICA | 2 = AMERICA | 4 = ANTARCTICA | 8 = ARCTIC | 16 = ASIA | 32 = ATLANTIC | 64 = AUSTRALIA | 128 = EUROPE | 256 = INDIAN | 512 = PACIFIC | 1024 = UTC | 2047 = ALL | 4095 = ALL_WITH_BC | 4096 = PER_COUNTRY Syntax: array timezone_identifiers_list( int $datetimezone, string $country ) Example 1: This example illustrates how to select the timezone listed in dropdown using timezone identifiers. php <?php function select_Timezone($selected = '') { // Create a list of timezone $OptionsArray = timezone_identifiers_list(); $select= '<select name="SelectContacts"> <option disabled selected> Please Select Timezone </option>'; while (list ($key, $row) = each ($OptionsArray) ){ $select .='<option value="'.$key.'"'; $select .= ($key == $selected ? : ''); $select .= '>'.$row.'</option>'; } $select.='</select>'; return $select; } echo select_Timezone() . '<br>'; ?> Output: Example 2: This example illustrates how to select the timezone listed in dropdown using timezone identifiers. php <?php // Create a timezone identifiers $timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::ALL); echo "<select>"; echo "<option disabled selected> Please Select Timezone </option>"; $n = 425; for($i = 0; $i < $n; $i++) { // Print the timezone identifiers echo "<option value='" . $timezone_identifiers[$i] . "'>" . $timezone_identifiers[$i] . "</option>"; } echo "</select>"; ?> Output: Example 3: This example illustrates the dropdown with list of TimeZone using DateTimeZone::listIdentifiers (DateTimeZone::ALL) along with range() function. php <?php $timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::ALL); $Africa = range(0, 51); $America = range(52, 198); $Asia = range(211, 292); $tz_stamp = time(); echo "<center><select style='padding:20px; font-family: Courier New, Courier, monospace; width: 450px;border:2px solid #a09; outline: none;'>"; echo "<option style='color:#FFF;font-family:Cambria; background-color:#a09;'><h3>Africa</h3> </option>"; foreach($Africa as $x) { $tzone[$x] = date_default_timezone_set( $timezone_identifiers[$x]); echo "<option>" . $timezone_identifiers[$x] . ' @ ' . date('P', $tz_stamp);"</option>"; } echo "<option style='color:#FFF;font-family:Cambria; background-color:#a09;font-size:15px;'> <h3>America</h3></option>"; foreach($America as $x) { $tzone[$x] = date_default_timezone_set( $timezone_identifiers[$x]); echo "<option>" . $timezone_identifiers[$x] . ' @ ' . date('P', $tz_stamp);"</option>"; } echo "<option style='color:#FFF;font-family:Cambria; background-color:#a09;font-size:15px;'> <h3>Asia</h3></option>"; foreach($Asia as $x) { $tzone[$x] = date_default_timezone_set( $timezone_identifiers[$x]); echo "<option>" . $timezone_identifiers[$x] . ' @ ' . date('P', $tz_stamp);"</option>"; } echo "</select></center>"; ?> Output: Reference: https://www.php.net/manual/en/function.timezone-identifiers-list.php Comment More infoAdvertise with us Next Article How to generate a drop down list of timezone using PHP ? V VigneshKannan3 Follow Improve Article Tags : Web Technologies PHP Similar Reads How to use the Date and Time in PHP ? Date and time handling in PHP is crucial for various web applications, ranging from simple date displays to complex calculations involving time zones and intervals. PHP provides a rich set of functions and classes to manage dates and times efficiently. Understanding these functionalities enables dev 2 min read How to set timezone offset using JavaScript ? The timezone offset represents the difference in minutes between local time and Coordinated Universal Time (UTC). Here are two different ways to set the timezone offset in JavaScript.1. Using getTimezoneOffset() MethodThe getTimezoneOffset() method is used to find the timezone offset. It returns the 2 min read How to add date and time picker using only one tag in HTML ? The date picker in HTML is a convenient tool that enhances user experience by allowing users to select a date from a dropdown menu rather than typing it manually. By using the <input> element with the type attribute set to "date", you can generate an interactive date picker in your HTML docume 2 min read How to convert DateTime to String using PHP ? Converting a `DateTime` to a string in PHP involves formatting the `DateTime` object into a human-readable format using the `format()` method. This process allows you to represent dates and times as strings in various formats, such as Y-m-d H:i:s. There are some following approachesTable of ContentB 4 min read How to add a date picker in form using HTML ? To add a date picker in a form using HTML, you can use the <input> element with the type attribute set to "date". A date picker is an interactive dropdown that makes it easy to choose the date from a calendar instead of typing it manually. In this article, we will learn how to add a date picke 2 min read Like