PHP timezone_location_get() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Date/Time

Definition

In PHP, timezone_location_get() returns location information for a time zone, such as its country code and its latitude and longitude.

The result is an array with four keys: country_code, latitude, longitude and comments. It only works with identifier-style zones like Europe/Paris. For zones created from an offset or an abbreviation, it returns false. It is the procedural version of DateTimeZone::getLocation().

Syntax

Call timezone_location_get() with the values you need. Start with this line.

PHP
$loc = timezone_location_get($tz);
CallWhat it does
timezone_location_get($tz)Returns the location array for the DateTimeZone object $tz.
timezone_location_get($tz)['country_code']Reads just the two-letter country code.
$tz->getLocation()The object-oriented version that returns the same array.

Always check the result before you use it, because the function returns false for zones that have no location, such as a plain offset like +02:00.

Library declarations
PHP
timezone_location_get(DateTimeZone $object): array|false

Parameters

ParameterDescription
objectRequired. A DateTimeZone object, usually created with timezone_open() or new DateTimeZone().

Return Value

Return ValueDescription
arrayAn array with country_code (string), latitude (float), longitude (float) and comments (string).
falseReturned when the time zone has no location data, for example when it was created from an offset.

PHP Examples

Example 1 — Reading the Country Code

Create a time zone for London and read its location data.

PHP
<?php
$tz = new DateTimeZone('Europe/London');
$loc = timezone_location_get($tz);

echo $loc['country_code'], PHP_EOL;
echo implode(', ', array_keys($loc)), PHP_EOL;

How It Works

  1. The DateTimeZone object represents the Europe/London zone.
  2. timezone_location_get() returns an array of location details.
  3. The country code for London is GB.
  4. array_keys() lists the four keys that every location array contains.

Example 2 — Checking the Coordinates

The latitude and longitude are floats. Because the exact decimals can vary, this example checks that they fall in the expected range for Paris.

PHP
<?php
$tz = timezone_open('Europe/Paris');
$loc = timezone_location_get($tz);

echo $loc['country_code'], PHP_EOL;
var_dump(is_float($loc['latitude']));
var_dump($loc['latitude'] > 48 && $loc['latitude'] < 49);
var_dump($loc['longitude'] > 2 && $loc['longitude'] < 3);

How It Works

  1. timezone_open() creates the DateTimeZone object for Europe/Paris.
  2. The country code is FR for France.
  3. The latitude is a float, and Paris sits between 48 and 49 degrees north.
  4. The longitude is between 2 and 3 degrees east.

Example 3 — Zones Without a Location

Not every time zone has a real place. UTC has placeholder values, and an offset-only zone returns false.

PHP
<?php
$utc = timezone_location_get(new DateTimeZone('UTC'));
var_dump($utc['country_code']);

$offset = timezone_location_get(new DateTimeZone('+02:00'));
var_dump($offset);

How It Works

  1. UTC is a valid identifier, so PHP returns an array for it.
  2. Because UTC is not tied to a country, the country code is the placeholder ??.
  3. The zone +02:00 is only an offset and has no location data.
  4. For that kind of zone the function returns false, so always test for false before reading the array.

Frequently Asked Questions

It returns an array with country_code, latitude, longitude and comments for a time zone, or false when the zone has no location information.
This happens when the DateTimeZone was created from a UTC offset such as +02:00 or from an abbreviation such as EST. Only identifier-based zones like Europe/Paris carry location data.
They are the coordinates of a representative place for the time zone, usually a main city. They are not precise borders.
Yes. The function is the procedural alias of the DateTimeZone::getLocation() method and returns the same result.
It means the time zone does not belong to a single country. UTC is the usual example.

Next: timezone_name_from_abbr()

timezone_name_from_abbr() returns a time zone name that matches an abbreviation, such as C.

timezone_name_from_abbr() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful