DateTimeZone::__construct
timezone_open
新しい DateTimeZone オブジェクトを作成する
&reftitle.description;
&style.oop;
public DateTimeZone::__construct
stringtimezone
&style.procedural;
DateTimeZonefalsetimezone_open
stringtimezone
新しい DateTimeZone オブジェクトを作成します。
DateTimeZone オブジェクトは、
3つの異なるタイムゾーンルールへのアクセスを提供します。
ひとつは
UTC からのオフセット (type 1),
もうひとつはタイムゾーンの省略形 (type
2),
そして IANA タイムゾーンデータベースで公開されている
タイムゾーン名
(type 3) です。
DateTimeZone オブジェクトは、
DateTime や
DateTimeImmutable に設定できます。
こうすることで、
ローカルのタイムゾーンとしてカプセル化された、
タイムゾーンを表示させることができます。
&reftitle.parameters;
timezone
サポートするタイムゾーン名
のいずれかや、
オフセット値 (+0200)、
またはタイムゾーンの省略名(BST)。
&reftitle.returnvalues;
成功した場合に DateTimeZone を返します。
&return.falseforfailure.style.procedural;
&reftitle.errors;
このメソッドは、指定したタイムゾーンが無効な形式だった場合に
Exception をスローします。
&reftitle.examples;
DateTimeZone を作成し、DateTimeImmutable に設定する
setTimezone($tzo);
echo $local->format(DateTimeInterface::RFC2822 . ' — e'), "\n";
}
?>
]]>
&example.outputs;
Thu, 02 Jun 2022 16:44:48 +0100 — Europe/London
Thu, 02 Jun 2022 20:29:48 +0445 — +04:45
Thu, 02 Jun 2022 09:44:48 -0600 — -06:00
Thu, 02 Jun 2022 17:44:48 +0200 — CEST
DateTimeZone のインスタンスを作成する際のエラー処理
getMessage() . '
';
}
}
?>
]]>
&example.outputs;