timezone_identifiers_list()

1. 定义

该函数返回所有时区库中包含的时区。 返回一个包含所有时区名的数字索引数组。

2. 语法

public static DateTimeZone::listIdentifiers ([ int $what = DateTimeZone::ALL [, string $country = NULL ]] ) : array

timezone_identifiers_list ([ int $what = DateTimeZone::ALL [, string $country = NULL ]] ) : array

3. 参数说明

参数 可选性 数据类型 描述
$what 可选 整型 DateTimeZone类常量之一
$country 可选 字符串 两个字母组成的国家代码

其中,$what参数有以下几个可选值:

  • AFRICA:1
  • AMERICA:2
  • ANTARCTICA:4
  • ARCTIC:8
  • ASIA:16
  • ATLANTIC:32
  • AUSTRALIA:64
  • EUROPE:128
  • INDIAN:256
  • PACIFIC:512
  • UTC:1024
  • ALL:2047
  • ALL_WITH_BC:4095
  • PER_COUNTRY:4096

4. 示例

<?php

// timezone_identifiers_list()
// 该函数返回所有时区库中包含的时区

// 面向对象式
$timezone_identifiers = DateTimeZone::listIdentifiers();
var_dump($timezone_identifiers);
/* 输出:
...

  string(20) "Pacific/Port_Moresby"
  [417]=>
  string(17) "Pacific/Rarotonga"
  [418]=>
  string(14) "Pacific/Saipan"
  [419]=>
  string(14) "Pacific/Tahiti"
  [420]=>
  string(14) "Pacific/Tarawa"
  [421]=>
  string(17) "Pacific/Tongatapu"
  [422]=>
  string(12) "Pacific/Wake"
  [423]=>
  string(14) "Pacific/Wallis"
  [424]=>
  string(3) "UTC"
}
*/

// 面向过程式
$timezone_identifiers = timezone_identifiers_list();
var_dump($timezone_identifiers);
/* 输出:
...

  string(20) "Pacific/Port_Moresby"
  [417]=>
  string(17) "Pacific/Rarotonga"
  [418]=>
  string(14) "Pacific/Saipan"
  [419]=>
  string(14) "Pacific/Tahiti"
  [420]=>
  string(14) "Pacific/Tarawa"
  [421]=>
  string(17) "Pacific/Tongatapu"
  [422]=>
  string(12) "Pacific/Wake"
  [423]=>
  string(14) "Pacific/Wallis"
  [424]=>
  string(3) "UTC"
}
*/

5. 延展阅读