DateTimeZone::getLocation

timezone_location_get

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

DateTimeZone::getLocation -- timezone_location_get返回与时区相关的定位信息

说明

面向对象风格

public DateTimeZone::getLocation(): array|false

过程化风格

timezone_location_get(DateTimeZone $object): array|false

返回时区的位置信息,包含国家代码,经纬度和注释。

参数

object

仅过程化风格:由 timezone_open() 返回的 DateTimeZone 对象。

返回值

包含时区的位置信息的数组 或者在失败时返回 false

范例

示例 #1 DateTimeZone::getLocation() 函数的范例:

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

以上例程会输出:

Array
(
    [country_code] => CZ
    [latitude] => 50.08333
    [longitude] => 14.43333
    [comments] =>
)
Array
(
    [country_code] => CZ
    [latitude] => 50.08333
    [longitude] => 14.43333
    [comments] =>
)

参见

  • DateTimeZone::listIdentifiers() - 返回包含了所有时区标识符的数字索引数组,以获得所有支持的时区标识符的完整或部分列表
add a note add a note

User Contributed Notes 1 note

up
9
gwyneths at gmail dot com
10 years ago
Print comments associated with timezones for a specific country. In this example, print all the comments for Canadian timezones.

<?php
$timeZones
= DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'CA');
foreach (
$timeZones as $key => $zoneName )
{
   
$tz = new DateTimeZone($zoneName);
   
$loc = $tz->getLocation();
    print(
$zoneName . " = " . $loc['comments'] . "<br>");
}
?>

Output:
America/Atikokan = Eastern Standard Time - Atikokan, Ontario and Southampton I, Nunavut
America/Blanc-Sablon = Atlantic Standard Time - Quebec - Lower North Shore
America/Cambridge_Bay = Mountain Time - west Nunavut
America/Dawson = Pacific Time - north Yukon
America/Dawson_Creek = Mountain Standard Time - Dawson Creek & Fort Saint John, British Columbia
America/Edmonton = Mountain Time - Alberta, east British Columbia & west Saskatchewan
...(snip)...
To Top