timezone_name_from_abbr


world apg

RETURNS the timezone name from its abbreviation.



<?php

str
|false timezone_name_from_abbr ( str $abbr , 
                                                          
int $utcOffset = -1 , 
                                                          
int $isDST = -1 )


where, 


$abbr = Time zone abbreviation

$utcOffset 
= Offset from GMT in seconds

$isDST 
= Daylight saving time indicator


?>

 $abbr 


The supported $timezone or an offset value.



 $utcOffset 


$utcOffset = -1, by default, which means that first found time zone corresponding to $abbr is returned, otherwise exact offset is searched and only if not found then the first time zone with any offset is returned.



 $isDST 


$isDST = -1, by default, which means that whether the time zone has daylight saving, DST, or not is not taken into consideration when searching.

If $isDST = 1, then the $utcOffset is assumed to be an offset with daylight saving, DST, in effect.

If $isDST = 0, then $utcOffset is assumed to be an offset without daylight saving, DST, in effect.





If $abbr does not exist then the time zone is searched solely by the $utcOffset and $isDST.





This function returns FALSE on failure.

Most of the time, it displays only the first name of the list.



  1 EXERCISE   

<?php

echo 'PHP: ' . PHP_VERSION . '<br><br>';

$arr_abbr_lst = timezone_abbreviations_list();
$arr_keys_lst = array_keys($arr_abbr_lst);

foreach(
$arr_keys_lst as $abr01)
{
echo 
$abr01 . ' => ' . timezone_name_from_abbr($abr01) . '<br>';
}

?>

  2 EXERCISE   

<?php

$abr02 
= "acdt"; 

echo 
timezone_name_from_abbr($abr02) . '<br>';

?>

  3 EXERCISE   

<?php

$abr03 
= "";

$offset03 = 0;

$isdst03 = 1;
 
echo 
timezone_name_from_abbr($abr03, $offset03, $isdst03) . '<br>';

?>

  4 EXERCISE   

<?php
 
// Run this exercise several times
// For each new run a new result will be obtained

echo 'PHP: ' . PHP_VERSION . '<br><br>';

$arr_abbr_lst = timezone_abbreviations_list();
$arr_keys_lst = array_keys($arr_abbr_lst);

$cnt04 = count($arr_keys_lst);

$cnt04 = ($cnt04 - 1);

$xct04 = mt_rand(0, $cnt04);
 
echo 
$arr_keys_lst[$xct04] . ' => ' . 
timezone_name_from_abbr($arr_keys_lst[$xct04]) . '<br>';

?>