Change language

How can I create a dropdown list of timezones using PHP?

| |
The timezone_identifiers_list() function is used to generate a dropdown list of timezones from PHP. This function is used to return an indexed array containing all timezone identifiers. The datetimezone object is passed as a parameter to the timezone_identifiers_list() function and returns an indexed array on success or False on error. This function is an alias for the DateTimeZone::listIdentifiers() function. 
The timezone_identifiers_list() function uses its time zone and country constants to independently display the list of time zones. 
So the possible values ​​for the 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 shows how to select the time zone specified in the drop-down list using time zone identifiers. function select_Timezone ( $selected = ’ ’ ) { // Create a list of time zones $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().
;  
?>
Output: Example 2:This example shows how to select the time zone specified in the dropdown using the time zone IDs.  
// Create time zone 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 time zone identifiers echo "< option value =’ " . $timezone_identifiers [ $i ]. "’ > " . $timezone_identifiers [ $i ]. "< / option >" ; } echo "< / select >" ;  
?>
Output: Example 3:This example illustrates a TimeZone combo box using DateTimeZone::listIdentifiers (DateTimeZone::ALL) along with the range() function. $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;’ >

Africa

< / 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; ’>

America

< / 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; ’>

Asia

< / 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: Link : https://www.php.net/manual /en/function.timezone-identifiers-list.php
SO 1 data error