Search
  1. DateTimeZoneクラス〔タイムゾーンを表す〕
  2. 定義済み定数
  3. DateTimeZone::__construct〔新しい DateTimeZone オブジェクトを作成する〕
  4. DateTimeZone::getLocation ※PHP v5.3.0+〔タイムゾーンの位置情報を返す〕
  5. DateTimeZone::getName〔タイムゾーンの名前を返す〕
  6. DateTimeZone::getOffset〔GMT からのタイムゾーンのオフセットを返す〕
  7. DateTimeZone::getTransitions〔タイムゾーンの変遷を返す〕
  8. DateTimeZone::listAbbreviations〔夏時間、オフセットおよびタイムゾーン名を含む連想配列を返す〕
  9. DateTimeZone::listIdentifiers ※PHP v5.3.0+〔すべてのタイムゾーン識別子を含む配列を返す〕

DateTimeZoneクラス
タイムゾーンを表す

unknown

DateTimeZone {
  /* 定数 */
  const integer DateTimeZone::AFRICA=1;
  const integer DateTimeZone::AMERICA=2;
  const integer DateTimeZone::ANTARCTICA=4;
  const integer DateTimeZone::ARCTIC=8;
  const integer DateTimeZone::ASIA=16;
  const integer DateTimeZone::ATLANTIC=32;
  const integer DateTimeZone::AUSTRALIA=64;
  const integer DateTimeZone::EUROPE=128;
  const integer DateTimeZone::INDIAN=256;
  const integer DateTimeZone::PACIFIC=512;
  const integer DateTimeZone::UTC=1024;
  const integer DateTimeZone::ALL=2047;
  const integer DateTimeZone::ALL_WITH_BC=4095;
  const integer DateTimeZone::PER_COUNTRY=4096;

  /* メソッド */
  __construct ( string $タイムゾーン )
  public array getLocation ( void )
  public string getName ( void )
  int getOffset ( DateTime $datetime )
  array getTransitions ( [ int $開始時のタイムスタンプ[, int $終了時のタイムスタンプ ]] )
  array listAbbreviations ( void )
  array listIdentifiers ( int $what=DateTime::ALL[, string $country=NULL ]] )
}

定義済み定数

unknown

DateTimeZoneノード型

DateTimeZone::AFRICA
アフリカのタイムゾーン
DateTimeZone::AMERICA
アメリカのタイムゾーン
DateTimeZone::ANTARCTICA
南極のタイムゾーン
DateTimeZone::ARCTIC
北極のタイムゾーン
DateTimeZone::ASIA
アジアのタイムゾーン
DateTimeZone::ATLANTIC
大西洋のタイムゾーン
DateTimeZone::AUSTRALIA
オーストラリアのタイムゾーン
DateTimeZone::EUROPE
ヨーロッパのタイムゾーン
DateTimeZone::INDIAN
インドのタイムゾーン
DateTimeZone::PACIFIC
太平洋のタイムゾーン
DateTimeZone::UTC
UTC タイムゾーン
DateTimeZone::ALL
すべてのタイムゾーン
DateTimeZone::ALL_WITH_BC
過去との互換性を保つものを含むすべてのタイムゾーン
DateTimeZone::PER_COUNTRY
国ごとのタイムゾーン

DateTimeZone::__construct
新しい DateTimeZone オブジェクトを作成する

unknown

DateTimeZone::__construct ( string $タイムゾーン )

新しいDateTimeZoneオブジェクトを返します。
指定したタイムゾーンが無効な形式の場合は、Exceptionが発生します。

<?
# DateTimeZone のインスタンスを作成する際のエラー処理
// エラー処理は、例外をキャッチして行う
$timezones = array('Europe/London''Mars/Phobos''Jupiter/Europa');

foreach ($timezones as $tz) {
    try {
        $mars = new DateTimeZone($tz);
    } catch(Exception $e) {
        echo $e->getMessage() . '<br>';
    }
}
/*
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos)
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)
*/
?>

DateTimeZone::getLocation ※PHP v5.3.0+
タイムゾーンの位置情報を返す

unknown

public array DateTimeZone::getLocation ( void )

timezone_location_get()関数は、DateTimeZone::getLocationのエイリアスです。

タイムゾーンの位置情報(国コード、緯度/経度、コメント)を含む配列を返します。

<?
$tz = new DateTimeZone("Europe/Prague");
print_r($tz->getLocation());
/*
Array
(
    [country_code] => CZ
    [latitude] => 50.08333
    [longitude] => 14.43333
    [comments] => 
)
*/
?>

DateTimeZone::getName
タイムゾーンの名前を返す

unknown

public string datetimezone_getlocation ( void )

timezone_name_get()関数は、DateTimeZone::getNameのエイリアスです。

タイムゾーンの名前を返します。

<?
$tz = new DateTimeZone("Asia/Tokyo");
echo $tz->getName(); // Asia/Tokyo
?>

DateTimeZone::getOffset
GMT からのタイムゾーンのオフセットを返す

unknown

int DateTimeZone::getOffset ( DateTime $datetime )
int timezone_offset_get ( DateTimeZone $object, DateTime $datetime )

timezone_offset_get()関数は、 DateTimeZone::getOffsetのエイリアスです。

datetimeに指定した日付/時刻についてのGMTへのオフセット秒数を返します。 GMTオフセットの計算の際には、使用するDateTimeZoneオブジェクトに含まれるタイムゾーン情報を使用します。 失敗した場合はFALSEを返します。

objectには、timezone_open()が返すDateTimeZoneオブジェクトを指定します。
timestamp_beginには、オフセットを計算する日付/時刻を含むDateTimeオブジェクトを指定します。

<?
// ふたつのタイムゾーンオブジェクトを作成する
// ひとつは台北 (台湾)、
// もうひとつは東京 (日本) 
$dateTimeZoneTaipei = new DateTimeZone("Asia/Taipei");
$dateTimeZoneJapan = new DateTimeZone("Asia/Tokyo");

// 同一の Unixタイムスタンプを持つふたつの DateTimeオブジェクトを作成する
// しかし付属するタイムゾーンはそれぞれ異なる
$dateTimeTaipei = new DateTime("now"$dateTimeZoneTaipei);
$dateTimeJapan = new DateTime("now"$dateTimeZoneJapan);

// $dateTimeTaipei オブジェクトに含まれる 日付/時刻 の GMT オフセットを計算する
// しかし、タイムゾーンの規則は東京のもの ($dateTimeZoneJapan)を使用
$timeOffset $dateTimeZoneJapan->getOffset($dateTimeTaipei);

// Sat Sep 8 01:00:00 1951 JST 以降の日付の場合
var_dump($timeOffset); // int(32400)
?>

DateTimeZone::getTransitions
タイムゾーンの変遷を返す

unknown

array DateTimeZone::getTransitions ( [ int $開始時のタイムスタンプ[, int $終了時のタイムスタンプ ]] )
array timezone_transitions_get ( DateTime $object[, int $timestamp_begin[, int $終了時のタイムスタンプ ]] )

timezone_transitions_get()関数は、DateTimeZone::getTransitionsのエイリアスです。

タイムゾーンの変遷を表す連想配列を返します。 失敗した場合はFALSEを返します。

objectには、timezone_open()が返すDateTimeZoneオブジェクトを指定します。

PHP v5.3.0から、オプション引数が追加されました。

<?
$timezone = new DateTimeZone("CET");
print_r(reset($timezone->getTransitions()));
/*
Array
(
    [ts] => -1693706400
    [time] => 1916-04-30T22:00:00+0000
    [offset] => 7200
    [isdst] => 1
    [abbr] => CEST
)
*/
?>
<?
date_default_timezone_set('Asia/Tokyo');
$tz = new DateTimeZone("PST");

foreach (timezone_transitions_get($tz) as $tr)
    if ($tr['ts'] > time())
        break;

$d = new DateTime"@{$tr['ts']});
printf("The timezone %s switches to %s on %s.\nThe new GMT offset will be: %d (%s)\n",
    $tz->getName(), $tr['isdst'] ? "DST" "standard time",
    $d->format('d M Y @ H:i'), $tr['offset'], $tr['abbr']
);
/*
The timezone America/Los_Angeles switches to standard time on 01 Nov 2009 @ 09:00.
The new GMT offset will be: -28800 (PST)
*/
?>

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

unknown

array DateTimeZone::listAbbreviations ( void )
array timezone_abbreviations_list ( void )

timezone_abbreviations_list()関数は、DateTimeZone::listAbbreviationsのエイリアスです。

夏時間、オフセット、タイムゾーン名を含む連想配列を返します。 失敗した場合はFALSEを返します。

<?
$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
        )

)
*/
?>

DateTimeZone::listIdentifiers ※PHP v5.3.0+
すべてのタイムゾーン識別子を含む配列を返す

unknown

array DateTimeZone::listIdentifiers ( [ int $what[, string $contry ]] )
array timezone_identifiers_list ( int $what[, string $country ]] )

timezone_identifiers_list()関数は、DateTimeZone::listIdentifiersのエイリアスです。

すべてのタイムゾーン識別子を含む配列を返します。 失敗した場合はFALSEを返します。

objectには、date_create()が返すDateTimeオブジェクトを指定します。

whatには、DateTimeZoneのクラス定数のいずれかを指定します。 デフォルトは、DateTimeZone::ALLです。

countryには2文字のISO 3166-1互換の国コードを指定します。

<?
$timezone_identifiers DateTimeZone::listIdentifiers();
for ($i=0$i 5$i++) {
    echo "$timezone_identifiers[$i]\n";
}
/*
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
*/
?>

関連コンテンツ

Q. このサイトの情報はお役に立ちましたでしょうか?

投票する 投票結果を見る

管理人に【web拍手】を送るweb拍手(1行メッセージも送れます♪)

pagetop

polarized women