php8.5
Home/ Manual/ datetime / datetimezone/ DateTimeZone::getLocation

DateTimeZone::getLocation

PHP function Edit on GitHub ✎

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

Returns location information for a timezone

Description

Oop

DateTimeZone::getLocation(): array|false

Procedural

timezone_location_get(DateTimeZone $object): array|false

Returns location information for a timezone, including country code, latitude/longitude and comments.

Parameters

Return Values

Array containing location information about timezoneFalseforfailure.

Examples

DateTimeZone::getLocation() example

php
<?php
$tz = new DateTimeZone("Asia/Jakarta");
print_r($tz->getLocation());
print_r(timezone_location_get($tz));

The above example will output:

output
Array
(
    [country_code] => ID
    [latitude] => -6.16667
    [longitude] => 106.8
    [comments] => Java, Sumatra
)
Array
(
    [country_code] => ID
    [latitude] => -6.16667
    [longitude] => 106.8
    [comments] => Java, Sumatra
)

The country_code elements contains the ISO 3166-1 alpha-2 country code for each entry. The latitude and longitude elements the coordinates of the named city from the time zone identifier, and comments contain (when not false) a hint of where in the given country this timezone applies. This information is suitable to present to end-users.

See Also

Source: reference/datetime/datetimezone/getlocation.xml · from the official PHP manual (php/doc-en)