PHP | timezone_name_from_abbr() Function

PHP timezone_name_from_abbr() Function


Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the PHP timezone_name_from_abbr() Function.

The timezone_name_from_abbr() function is used to get the name of timezone from an abbreviation.

Syntax

Following below is the syntax to use this function -

timezone_name_from_abbr($abbr, [$gmtoffset[, $isdst]]);


Parameter Details

Sr.NoParameter & Description
1

abbr (Mandatory)

This is a string value representing the abbreviation for which you need to know the name of the time zone .

2

gmtOffset (Optional)

This is an integer value representing an offset from GMT in seconds. If a value for this is given then its timezone is searched and returned. If not found first found timezone (according to given abbreviation) is returned.

3

isdst (Optional)

This is an integer value specifying the daylight saving of the timezone. If value passed for this parameter is 0 it indicates that there is no daylight saving, if it is 1 there is a dalight saving and, if it is 0 the day light saving is not considered.

Return Value

This function returns a string value representing the name of a time zone. In case of failure, it returns the boolean value false.

PHP Version

This function was first introduced as part of core PHP v 5.2.0 and, it works with all the later versions.

Example1

Below example shows the usage of the timezone_name_from_abbr() function -

<?php
   $res = timezone_name_from_abbr("PST");   
   print($res);
?>

Output

When the above code is executed, it will produce the following result -

America/Los_Angeles

Example2

You could also get the timezone name by passing the offset value as follows -

<?php
   //setting the timezone
   $res = timezone_name_from_abbr("", 3600, 0);   
   print($res);
?>

Output

When the above code is executed, it will produce the following result -

Europe/Paris

Example3

Try the following example -

echo timezone_name_from_abbr("CET")."\n";
echo timezone_name_from_abbr("", 3600, 0);

Output

When the above code is executed, it will produce the following result -

Europe/Berlin
Europe/Paris


Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the timezone_name_get() Function in PHP.

Do feel free to ask your questions where necessary and i will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.

Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.

Thanks for reading and bye for now.