<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.datetimezone.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'datetimezone.construct.php',
    1 => 'DateTimeZone::__construct',
    2 => 'Creates new DateTimeZone object',
  ),
  'up' => 
  array (
    0 => 'class.datetimezone.php',
    1 => 'DateTimeZone',
  ),
  'prev' => 
  array (
    0 => 'class.datetimezone.php',
    1 => 'DateTimeZone',
  ),
  'next' => 
  array (
    0 => 'datetimezone.getlocation.php',
    1 => 'DateTimeZone::getLocation',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/datetime/datetimezone/construct.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="datetimezone.construct" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeZone::__construct</h1>
  <h1 class="refname">timezone_open</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeZone::__construct</span> -- <span class="refname">timezone_open</span> &mdash; <span class="dc-title">Creates new DateTimeZone object</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetimezone.construct-description">
  <h3 class="title">Descrizione</h3>
  <p class="para">Stile orientato agli oggetti</p>
  <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeZone::__construct</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$timezone</code></span>)</div>

  <p class="para rdfs-comment">Stile procedurale</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><a href="function.timezone-open.php" class="methodname">timezone_open</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$timezone</code></span>): <span class="type"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="para rdfs-comment">
   Creates a new DateTimeZone object.
  </p>
  <p class="para">
   A DateTimeZone object provides access to three different types of timezone
   rules: UTC offset (type <code class="literal">1</code>), timezone abbreviation (type
   <code class="literal">2</code>), and <a href="timezones.php" class="link">timezone
   identifiers</a> as published in the IANA timezone database
   (type <code class="literal">3</code>).
  </p>
  <p class="para">
   The DateTimeZone object can be attached to <span class="classname"><a href="class.datetime.php" class="classname">DateTime</a></span> and
   <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> objects to be able to render the
   timezone encapsulated by these objects in a local timezone.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetimezone.construct-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">timezone</code></dt>
     <dd>
      <p class="para">
       One of the supported <a href="timezones.php" class="link">timezone names</a>,
       an offset value (+0200), or a timezone abbreviation (BST).
      </p>
     </dd>
    
   </dl>
  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-datetimezone.construct-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Returns <span class="classname"><a href="class.datetimezone.php" class="classname">DateTimeZone</a></span> on success.
   Stile procedurale restituisce <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> in caso di fallimento.
  </p>
 </div>

 
 <div class="refsect1 errors" id="refsect1-datetimezone.construct-errors">
  <h3 class="title">Errori/Eccezioni</h3>
  <p class="para">
   This method throws
   <span class="exceptionname"><a href="class.dateinvalidtimezoneexception.php" class="exceptionname">DateInvalidTimeZoneException</a></span> if the timezone supplied is not
   recognised as a valid timezone. Prior to PHP 8.3, this was an
   <span class="exceptionname"><a href="class.exception.php" class="exceptionname">Exception</a></span> instead.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetimezone.construct-changelog">
  <h3 class="title">Log delle modifiche</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.3.0</td>
       <td>
        Invalid values now return a
        <span class="exceptionname"><a href="class.dateinvalidtimezoneexception.php" class="exceptionname">DateInvalidTimeZoneException</a></span> instead of
        a generic <span class="exceptionname"><a href="class.exception.php" class="exceptionname">Exception</a></span>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-datetimezone.construct-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Creating and attaching DateTimeZone to a DateTimeImmutable</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$d </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">(</span><span style="color: #DD0000">"2022-06-02 15:44:48 UTC"</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">$timezones </span><span style="color: #007700">= [ </span><span style="color: #DD0000">'Europe/London'</span><span style="color: #007700">, </span><span style="color: #DD0000">'GMT+04:45'</span><span style="color: #007700">, </span><span style="color: #DD0000">'-06:00'</span><span style="color: #007700">, </span><span style="color: #DD0000">'CEST' </span><span style="color: #007700">];<br /><br />foreach (</span><span style="color: #0000BB">$timezones </span><span style="color: #007700">as </span><span style="color: #0000BB">$tz</span><span style="color: #007700">) {<br />    </span><span style="color: #0000BB">$tzo </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #0000BB">$tz</span><span style="color: #007700">);<br /><br />    </span><span style="color: #0000BB">$local </span><span style="color: #007700">= </span><span style="color: #0000BB">$d</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">setTimezone</span><span style="color: #007700">(</span><span style="color: #0000BB">$tzo</span><span style="color: #007700">);<br />    echo </span><span style="color: #0000BB">$local</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #0000BB">DateTimeInterface</span><span style="color: #007700">::</span><span style="color: #0000BB">RFC2822 </span><span style="color: #007700">. </span><span style="color: #DD0000">' — e'</span><span style="color: #007700">) . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">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</pre>
</div>
    </div>
   </div>
  </p>

  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Example #2 Catching errors when instantiating <span class="classname"><a href="class.datetimezone.php" class="classname">DateTimeZone</a></span></strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">// Error handling by catching exceptions<br /></span><span style="color: #0000BB">$timezones </span><span style="color: #007700">= array(</span><span style="color: #DD0000">'Europe/London'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Mars/Phobos'</span><span style="color: #007700">, </span><span style="color: #DD0000">'Jupiter/Europa'</span><span style="color: #007700">);<br /><br />foreach (</span><span style="color: #0000BB">$timezones </span><span style="color: #007700">as </span><span style="color: #0000BB">$tz</span><span style="color: #007700">) {<br />    try {<br />        </span><span style="color: #0000BB">$mars </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeZone</span><span style="color: #007700">(</span><span style="color: #0000BB">$tz</span><span style="color: #007700">);<br />        echo </span><span style="color: #0000BB">$mars</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getName</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />    } catch(</span><span style="color: #0000BB">Exception $e</span><span style="color: #007700">) {<br />        echo </span><span style="color: #0000BB">$e</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getMessage</span><span style="color: #007700">() . </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />    }<br />}</span></span></code></div>
    </div>

    <div class="example-contents"><p>Il precedente esempio visualizzerà:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">Europe/London
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Mars/Phobos)
DateTimeZone::__construct() [datetimezone.--construct]: Unknown or bad timezone (Jupiter/Europa)</pre>
</div>
    </div>
   </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>