DateTimeZone::__construct
(PHP 5 >= 5.2.0)
DateTimeZone::__construct — 新しい DateTimeZone オブジェクトを作成する
説明
DateTimeZone::__construct
( string $timezone
)
新しい DateTimeZone オブジェクトを作成します。
返り値
成功した場合に DateTimeZone を返します。
エラー / 例外
このメソッドは、指定したタイムゾーンが無効な形式だった場合に Exception をスローします。
例
例1 DateTimeZone のインスタンスを作成する際のエラー処理
<?php
// エラー処理は、例外をキャッチすることで行います
$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::__construct
There are no user contributed notes for this page.
