downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DateInterval> <DateTimeZone::listAbbreviations
[edit] Last updated: Fri, 10 Feb 2012

view this page in

DateTimeZone::listIdentifiers

timezone_identifiers_list

(PHP 5 >= 5.2.0)

DateTimeZone::listIdentifiers -- timezone_identifiers_listReturns numerically index array with all timezone identifiers

Description

Object oriented style

public static array DateTimeZone::listIdentifiers ([ int $what = DateTimeZone::ALL [, string $country = NULL ]] )

Procedural style

array timezone_identifiers_list ([ int $what = DateTimeZone::ALL [, string $country = NULL ]] )

Parameters

what

One of DateTimeZone class constants.

country

A two-letter ISO 3166-1 compatible country code.

Note: This option is only used when what is set to DateTimeZone::PER_COUNTRY.

Return Values

Returns array on success or FALSE on failure.

Changelog

Version Description
5.3.0 Added the optional what and country parameters.

Examples

Example #1 A timezone_identifiers_list() example

<?php
$timezone_identifiers 
DateTimeZone::listIdentifiers();
for (
$i=0$i 5$i++) {
    echo 
"$timezone_identifiers[$i]\n";
}
?>

The above example will output something similar to:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara

See Also



add a note add a note User Contributed Notes DateTimeZone::listIdentifiers
neo22s at gmail dot com 31-Oct-2011 05:50
I normaly use this script to allow the user choose his timezone:

<?php
///timezones functions
function get_timezones()
{
    if (
method_exists('DateTimeZone','listIdentifiers'))
    {
       
$timezones = array();
       
$timezone_identifiers = DateTimeZone::listIdentifiers();
 
        foreach(
$timezone_identifiers as $value )
        {
            if (
preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $value ) )
            {
               
$ex=explode('/',$value);//obtain continent,city
               
$city = isset($ex[2])? $ex[1].' - '.$ex[2]:$ex[1];//in case a timezone has more than one
               
$timezones[$ex[0]][$value] = $city;
            }
        }
        return
$timezones;
    }
    else
//old php version
   
{
        return
FALSE;
    }
}
 
 
 
function
get_select_timezones($select_name='TIMEZONE',$selected=NULL)
{
   
$timezones = get_timezones();
   
$sel.='<select id="'.$select_name.'" name="'.$select_name.'">';
    foreach(
$timezones as $continent=>$timezone )
    {
       
$sel.= '<optgroup label="'.$continent.'">';
        foreach(
$timezone as $city=>$cityname )
        {           
            if (
$selected==$city)
            {
               
$sel.= '<option selected=selected value="'.$city.'">'.$cityname.'</option>';
            }
            else
$sel.= '<option value="'.$city.'">'.$cityname.'</option>';
        }
       
$sel.= '</optgroup>';
    }
   
$sel.='</select>';
 
    return
$sel;
}
?>
chema at garridodiaz dot com 19-Feb-2010 02:50
I use this time zone select:

<select id="TIMEZONE" name="TIMEZONE">
    <?php
    $timezone_identifiers
= DateTimeZone::listIdentifiers();
    foreach(
$timezone_identifiers as $value ){
        if (
preg_match( '/^(America|Antartica|Arctic|Asia|Atlantic|Europe|Indian|Pacific)\//', $value ) ){
           
$ex=explode("/",$value);//obtain continent,city   
           
if ($continent!=$ex[0]){
                if (
$continent!="") echo '</optgroup>';
                echo
'<optgroup label="'.$ex[0].'">';
            }
   
           
$city=$ex[1];
           
$continent=$ex[0];
            echo
'<option value="'.$value.'">'.$city.'</option>';               
        }
    }
   
?>
        </optgroup>
    </select>

 
show source | credits | stats | sitemap | contact | advertising | mirror sites