PHP Function Reference

PHP timezone_location_get() Function



The PHP timezone_location_get() function returns location information for a timezone, including country code, latitude/longitude and comments. This function is an alias of DateTimeZone::getLocation() method.

Syntax

//Object-oriented style
public DateTimeZone::getLocation()

//Procedural style
timezone_location_get(object)

Parameters

object Required. For procedural style only: A DateTimeZone object returned by timezone_open().

Return Value

Returns an array containing location information about timezone or false on failure.

Example: using both styles

The example below shows the usage of timezone_location_get() function.

<?php
  //creating a DateTimeZone object 
  $tz1 = timezone_open("Europe/London");

  //displaying the name of the timezone
  //using Object-oriented style
  print_r($tz1->getLocation());

  echo "\n";

  //creating a DateTimeZone object
  //using Procedural style 
  $tz2 = timezone_open("America/Chicago");

  //displaying the name of the timezone
  print_r(timezone_location_get($tz2));
?>

The output of the above code will be:

Array
(
    [country_code] => GB
    [latitude] => 51.50833
    [longitude] => -0.12527
    [comments] => 
)

Array
(
    [country_code] => US
    [latitude] => 41.85
    [longitude] => -87.65
    [comments] => Central (most areas)
)

❮ PHP Date and Time Reference