DateTimeZone::listAbbreviations

timezone_abbreviations_list

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

DateTimeZone::listAbbreviations -- timezone_abbreviations_list夏時間、オフセットおよびタイムゾーン名を含む連想配列を返す

説明

オブジェクト指向型

public static DateTimeZone::listAbbreviations(): array

手続き型

この関数が返す省略形のリストは、 歴史的に使われてきた値を全て含んでいます。 これは正しい値ではあるものの、混乱を招くものがあります。 値が衝突しているものもあります。たとえば PST はアメリカ合衆国(US)とフィリピンの双方で使われています。

よって、この関数が返すリストは、ユーザーにタイムゾーンを選択させる表示オプションを構築する目的には適していません。

注意:

この関数で使われるデータは、パフォーマンス上の理由でプリコンパイルされています。 よって、より新しい » timezonedb を使っていても更新されません。

パラメータ

この関数にはパラメータはありません。

戻り値

成功した場合に、タイムゾーンの情報を含んだ配列を返します。

例1 timezone_abbreviations_list() の例

<?php
$timezone_abbreviations
= DateTimeZone::listAbbreviations();
print_r($timezone_abbreviations["acst"]);
?>

上の例の出力は、 たとえば以下のようになります。

Array
(
    [0] => Array
        (
            [dst] => 1
            [offset] => -14400
            [timezone_id] => America/Porto_Acre
        )

    [1] => Array
        (
            [dst] => 1
            [offset] => -14400
            [timezone_id] => America/Eirunepe
        )

    [2] => Array
        (
            [dst] => 1
            [offset] => -14400
            [timezone_id] => America/Rio_Branco
        )

    [3] => Array
        (
            [dst] => 1
            [offset] => -14400
            [timezone_id] => Brazil/Acre
        )

)

参考

add a note add a note

User Contributed Notes 2 notes

up
62
jonathan at hogervorst dot info
10 years ago
This method returns an associative array containing some 'major' timezones (like CEST), which on their own contain more specific 'geographic' timezones (like Europe/Amsterdam).

If you're using these timezones and their offset/DST information, it's extremely important to realize the following:

*It seems like ALL DIFFERENT OFFSET/DST CONFIGURATIONS (including historical configurations) of each timezone are included!*

For example, Europe/Amsterdam can be found six times in the output of this function. Two occurrences (offset 1172/4772) are for the Amsterdam time used until 1937; two (1200/4800) are for the time that was used between 1937 and 1940; and two (3600/4800) are for the time used since 1940.

*Therefore, YOU CANNOT RELY ON THE OFFSET/DST INFORMATION RETURNED BY THIS FUNCTION as being currently correct/in use!*

If you want to know the current offset/DST of a certain timezone, you'll have to do something like this:

<?php
$now
= new DateTime(null, new DateTimeZone('Europe/Amsterdam'));
echo
$now->getOffset();
?>

P.S. I'm sorry for my use of caps lock in this post, but as this behavior is not described in the documentation, I considered it to be important enough to shout. Normally I don't do such things :)
up
-8
kingskippus at gmail dot com
15 years ago
Note that the dst field is of boolean type, so if you are doing an identity comparison, you need to test for true or false, not 0 or 1.  For example:

<?php
  $timezone_abbreviations
= DateTimeZone::listAbbreviations();
  foreach (
$timezone_abbreviations["est"] as $tz) {
    echo
$tz['timezone_id'];
   
// if ($tz['dst'] === 1) will always evaluate to false
   
if ($tz['dst'] === true) {
      echo
" (DST observed)<br />\n";
    }
   
// Could use else here, but for illustration...
   
if ($tz['dst'] === false) {
      echo
" (DST not observed)<br />\n";
    }
  }
?>
To Top