Tutorialspoint.dev

PHP | timezone_name_from_abbr() Function

The timezone_name_from_abbr() function is an inbuilt function in PHP which is used to return the timezone name from abbreviation. The abbreviation is sent as a parameter to the timezone_name_from_abbr() function and it returns the name of the timezone on success or False on failure.

Syntax:

string timezone_name_from_abbr( $abbr, $gmtoffset, $isdst )

Parameters: This function accepts three parameters as mentioned above and described below:

  • $abbr: It is a mandatory parameter which specifies the timezone abbreviation.
  • $gmtoffset: It is an optional parameter which specifies the offset from GMT in seconds. The default value is -1, which means that first found timezone corresponding to abbr is returned.
  • $isdst: It is an optional parameter which specifies the daylight saving time indicator. The default value is -1, which means that whether the timezone has daylight saving or not is not taken into consideration when searching.

Return Value: It returns the name of the timezone on success or False on failure.

Exceptions: The timezone_name_from_abbr() function is an alias of DateTimeZone::listAbbreviations function.



Below program illustrate the timezone_name_from_abbr() function in PHP:

Program 1:

<?php
  
// Displaying the name of timezone using the abbreviation
$abbr = timezone_name_from_abbr("PST");
echo ("PST stands for " . $abbr);
?>

Output:

PST stands for America/Los_Angeles

Program 2:

<?php
  
// Displaying the name of timezone using the abbreviation
$abbr = timezone_name_from_abbr("", 7200, 0);
echo ("The given parameter stands for " . $abbr);
?>

Output:

The given parameter stands for Europe/Helsinki

Related Articles:

Reference: http://php.net/manual/en/function.timezone-name-from-abbr.php



This article is attributed to GeeksforGeeks.org

leave a comment

code

0 Comments

load comments

Subscribe to Our Newsletter