mirror of
https://github.com/php/doc-de.git
synced 2026-03-24 07:12:15 +01:00
188 lines
5.3 KiB
XML
188 lines
5.3 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- EN-Revision: 3a8c3e77df070a046c9d5b56b68926ca2d7e5ee3 Maintainer: cmb Status: ready -->
|
|
<!-- Reviewed: yes -->
|
|
<!-- Rev-Revision: c7ee9cd4d1bb4538e283502b5f958b3042a61a63 Reviewer: samesch -->
|
|
<refentry xml:id="datetimezone.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>DateTimeZone::__construct</refname>
|
|
<refname>timezone_open</refname>
|
|
<refpurpose>Erstellt neues DateTimeZone-Objekt</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<para>&style.oop;</para>
|
|
<constructorsynopsis role="DateTimeZone">
|
|
<modifier>public</modifier> <methodname>DateTimeZone::__construct</methodname>
|
|
<methodparam><type>string</type><parameter>timezone</parameter></methodparam>
|
|
</constructorsynopsis>
|
|
<para>&style.procedural;</para>
|
|
<methodsynopsis>
|
|
<type class="union"><type>DateTimeZone</type><type>false</type></type><methodname>timezone_open</methodname>
|
|
<methodparam><type>string</type><parameter>timezone</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Erstellt neues DateTimeZone-Objekt.
|
|
</para>
|
|
<para>
|
|
Ein DateTimeZone-Objekt bietet Zugriff auf drei verschiedene Arten von
|
|
Zeitzonen-Regeln: UTC-Offset (Typ <literal>1</literal>),
|
|
Zeitzonen-Abkürzung (Typ <literal>2</literal>), und
|
|
<link linkend="timezones">Zeitzonen-Kennungen</link> wie in der
|
|
IANA-Zeitzonendatenbank angegeben (Typ <literal>3</literal>).
|
|
</para>
|
|
<para>
|
|
Das DateTimeZone-Objekt kann an <classname>DateTime</classname>- und
|
|
<classname>DateTimeImmutable</classname>-Objekte angehängt werden, um die
|
|
Zeitzone, die in diesen Objekten enthalten ist, in einer lokalen Zeitzone
|
|
wiederzugeben.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>timezone</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Eine der unterstützten
|
|
<link linkend="timezones">Zeitzonen-Kennungen</link>, ein Offset-Wert
|
|
(+0200) oder eine Zeitzonen-Abkürzung (BST).
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Gibt bei Erfolg ein <classname>DateTimeZone</classname>-Objekt zurück.
|
|
&return.falseforfailure.style.procedural;
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Wenn die angegebene Zeitzone als nicht korrekt eingestuft wird, wirft diese
|
|
Methode eine <exceptionname>DateInvalidTimeZoneException</exceptionname>.
|
|
Vor PHP 8.3 wird stattdessen eine <exceptionname>Exception</exceptionname>
|
|
geworfen.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<para>
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.3.0</entry>
|
|
<entry>
|
|
Ungültige Werte geben nun eine
|
|
<exceptionname>DateInvalidTimeZoneException</exceptionname> statt
|
|
einer allgemeinen <exceptionname>Exception</exceptionname> zurück.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Erstellen und Anhängen von DateTimeZone an ein DateTimeImmutable</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$d = new DateTimeImmutable("2022-06-02 15:44:48 UTC");
|
|
|
|
$timezones = [ 'Europe/London', 'GMT+04:45', '-06:00', 'CEST' ];
|
|
|
|
foreach ($timezones as $tz) {
|
|
$tzo = new DateTimeZone($tz);
|
|
|
|
$local = $d->setTimezone($tzo);
|
|
echo $local->format(DateTimeInterface::RFC2822 . ' — e') . "\n";
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
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
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title>Fehler beim Initialisieren von <classname>DateTimeZone</classname> abfangen</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Fehlerbehandlung durch Abfangen von Exceptions
|
|
$timezones = array('Europe/London', 'Mars/Phobos', 'Jupiter/Europa');
|
|
|
|
foreach ($timezones as $tz) {
|
|
try {
|
|
$mars = new DateTimeZone($tz);
|
|
echo $mars->getName() . "\n";
|
|
} catch(Exception $e) {
|
|
echo $e->getMessage() . "\n";
|
|
}
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Europe/London
|
|
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos)
|
|
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|