PHP | timezone_location_get() Function

The timezone_location_get() function is an inbuilt function in PHP which is used to return the location information for the given timezone. The date time object is sent as a parameter to the timezone_location_get() function and it returns location information related to the timezone on success or False on failure.

Syntax:

timezone_location_get( $object )

Parameters: This function accepts single parameter $object which is mandatory. It is used to specify the DateTimeZone object.



Return Value: This function returns the location information for a given timezone on success or False on failure.

Exception: The timezone_location_get() function is an alias of DateTimeZone::getLocation() function.

Below programs illustrate the timezone_location_get() function in PHP:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Opening a timezone
$timeZone = timezone_open("Asia/Kolkata");
  
// Displaying the location details of a timezone
echo "Location Details of the Specified Timezone: \n";
  
print_r(timezone_location_get($timeZone));
?>

chevron_right


Output:

Location Details of the Specified Timezone: 
Array
(
    [country_code] => IN
    [latitude] => 22.53333
    [longitude] => 88.36666
    [comments] => 
)

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
  
// Declaring a timezone
$timeZone = new DateTimeZone("Asia/Kolkata");
  
// Displaying the location details of a timezone
echo ("Location Details of the Specified Timezone:\n");
  
print_r($timeZone->getLocation());
?>

chevron_right


Output:

Location Details of the Specified Timezone:
Array
(
    [country_code] => IN
    [latitude] => 22.53333
    [longitude] => 88.36666
    [comments] => 
)

Related Articles:

Reference: http://php.net/manual/en/function.timezone-location-get.php



My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.