PHP Function Reference

PHP DateTimeZone - getLocation() Method



The PHP DateTimeZone::getLocation() method returns location information for a timezone, including country code, latitude/longitude and comments. The timezone_location_get() function is an alias of this 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 DateTimeZone::getLocation() method.

<?php
  //creating a DateTimeZone object 
  $tz1 = new DateTimeZone("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 = new DateTimeZone("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