<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/book.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'class.datetime.php',
    1 => 'DateTime',
    2 => 'La classe DateTime',
  ),
  'up' => 
  array (
    0 => 'book.datetime.php',
    1 => 'Date/Time',
  ),
  'prev' => 
  array (
    0 => 'datetime.examples-arithmetic.php',
    1 => 'Date/Time Arithmetic',
  ),
  'next' => 
  array (
    0 => 'datetime.add.php',
    1 => 'DateTime::add',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/datetime/datetime.xml',
  ),
  'history' => 
  array (
  ),
  'extra_header_links' => 
  array (
    'rel' => 'alternate',
    'href' => '/manual/en/feeds/class.datetime.atom',
    'type' => 'application/atom+xml',
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="class.datetime" class="reference">

 <h1 class="title">La classe DateTime</h1>
 

 <div class="partintro"><p class="verinfo">(PHP 5 &gt;= 5.2.0, PHP 7, PHP 8)</p>


  <div class="section" id="datetime.intro">
   <h2 class="title">Introduzione</h2>
   <p class="para">
    Rappresentazione di una data e ora.
   </p>
   <p class="para">
    Questa classe si comporta come <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span>,
    eccetto che gli oggetti si modificano quando vengono chiamati dei metodi
    di modifica come <span class="function"><a href="datetime.modify.php" class="function">DateTime::modify()</a></span>.
   </p>
   <div class="warning"><strong class="warning">Avviso</strong>
    <p class="para">
     Chiamare metodi sugli oggetti della classe <span class="classname"><strong class="classname">DateTime</strong></span>
     cambierà le informazioni incapsulate in questi oggetti, se si vuole
     prevenirlo si dovrà utilizzare l&#039;operatore <code class="literal">clone</code> per
     creare un nuovo oggetto. Utilizzare <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span>
     invece di <span class="classname"><strong class="classname">DateTime</strong></span> per ottenere questo comportamento
     raccomandato per impostazione predefinita.
    </p>
   </div>
  </div>


  <div class="section" id="datetime.synopsis">
   <h2 class="title">Sommario della classe</h2>


   <div class="classsynopsis"><div class="classsynopsisinfo">
    
     <span class="modifier">class</span> <strong class="classname"><strong class="classname">DateTime</strong></strong>
    

    
     <span class="modifier">implements</span>
      <a href="class.datetimeinterface.php" class="interfacename">DateTimeInterface</a> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Costanti ereditate */</div>
    <div class="fieldsynopsis">
     <span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.atom"><var class="varname">DateTimeInterface::ATOM</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.cookie"><var class="varname">DateTimeInterface::COOKIE</var></a></var><span class="initializer"> = &quot;l, d-M-Y H:i:s T&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601"><var class="varname">DateTimeInterface::ISO8601</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sO&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.iso8601-expanded"><var class="varname">DateTimeInterface::ISO8601_EXPANDED</var></a></var><span class="initializer"> = &quot;X-m-d\\TH:i:sP&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc822"><var class="varname">DateTimeInterface::RFC822</var></a></var><span class="initializer"> = &quot;D, d M y H:i:s O&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc850"><var class="varname">DateTimeInterface::RFC850</var></a></var><span class="initializer"> = &quot;l, d-M-y H:i:s T&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1036"><var class="varname">DateTimeInterface::RFC1036</var></a></var><span class="initializer"> = &quot;D, d M y H:i:s O&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc1123"><var class="varname">DateTimeInterface::RFC1123</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc7231"><var class="varname">DateTimeInterface::RFC7231</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s \\G\\M\\T&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc2822"><var class="varname">DateTimeInterface::RFC2822</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339"><var class="varname">DateTimeInterface::RFC3339</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rfc3339-extended"><var class="varname">DateTimeInterface::RFC3339_EXTENDED</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:s.vP&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.rss"><var class="varname">DateTimeInterface::RSS</var></a></var><span class="initializer"> = &quot;D, d M Y H:i:s O&quot;</span>;</div>
<div class="fieldsynopsis"><span class="modifier">public</span>
     <span class="modifier">const</span>
     <span class="type"><a href="language.types.string.php" class="type string">string</a></span>
      <var class="fieldsynopsis_varname"><a href="class.datetimeinterface.php#datetimeinterface.constants.w3c"><var class="varname">DateTimeInterface::W3C</var></a></var><span class="initializer"> = &quot;Y-m-d\\TH:i:sP&quot;</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Metodi */</div>
    <div class="constructorsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="datetime.construct.php" class="methodname">__construct</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$datetime</code><span class="initializer"> = &quot;now&quot;</span></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span></span> <code class="parameter">$timezone</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>)</div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.add.php" class="methodname">add</a></span>(<span class="methodparam"><span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="datetime.createfromformat.php" class="methodname">createFromFormat</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$datetime</code></span>, <span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span></span> <code class="parameter">$timezone</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="datetime.createfromimmutable.php" class="methodname">createFromImmutable</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimeimmutable.php" class="type DateTimeImmutable">DateTimeImmutable</a></span> <code class="parameter">$object</code></span>): <span class="type">static</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="datetime.createfrominterface.php" class="methodname">createFromInterface</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimeinterface.php" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$object</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.modify.php" class="methodname">modify</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$modifier</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="modifier">static</span> <span class="methodname"><a href="datetime.set-state.php" class="methodname">__set_state</a></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$array</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.setdate.php" class="methodname">setDate</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$year</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$month</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$day</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.setisodate.php" class="methodname">setISODate</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$year</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$week</code></span>, <span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$dayOfWeek</code><span class="initializer"> = 1</span></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.settime.php" class="methodname">setTime</a></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$hour</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$minute</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$second</code><span class="initializer"> = 0</span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$microsecond</code><span class="initializer"> = 0</span></span><br>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.settimestamp.php" class="methodname">setTimestamp</a></span>(<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$timestamp</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.settimezone.php" class="methodname">setTimezone</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimezone.php" class="type DateTimeZone">DateTimeZone</a></span> <code class="parameter">$timezone</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.sub.php" class="methodname">sub</a></span>(<span class="methodparam"><span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span> <code class="parameter">$interval</code></span>): <span class="type"><a href="class.datetime.php" class="type DateTime">DateTime</a></span></div>

    <div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.diff.php" class="methodname">diff</a></span>(<span class="methodparam"><span class="type"><a href="class.datetimeinterface.php" class="type DateTimeInterface">DateTimeInterface</a></span> <code class="parameter">$targetObject</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$absolute</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>): <span class="type"><a href="class.dateinterval.php" class="type DateInterval">DateInterval</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.format.php" class="methodname">format</a></span>(<span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter">$format</code></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.getoffset.php" class="methodname">getOffset</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.gettimestamp.php" class="methodname">getTimestamp</a></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.gettimezone.php" class="methodname">getTimezone</a></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>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.serialize.php" class="methodname">__serialize</a></span>(): <span class="type"><a href="language.types.array.php" class="type array">array</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="datetime.unserialize.php" class="methodname">__unserialize</a></span>(<span class="methodparam"><span class="type"><a href="language.types.array.php" class="type array">array</a></span> <code class="parameter">$data</code></span>): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>
<div class="methodsynopsis dc-description"><span class="attribute"><a href="class.deprecated.php">#[\Deprecated]</a> </span><br>
   <span class="modifier">public</span> <span class="methodname"><a href="datetime.wakeup.php" class="methodname">__wakeup</a></span>(): <span class="type"><a href="language.types.void.php" class="type void">void</a></span></div>

  }</div>


  </div>

 <div class="section" id="datetime.changelog">
  <h2 class="title">Log delle modifiche</h2>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Versione</th>
       <th>Descrizione</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>7.2.0</td>
       <td>
        Le costanti della classe <span class="classname"><strong class="classname">DateTime</strong></span> sono ora definite
        in <span class="classname"><a href="class.datetimeinterface.php" class="classname">DateTimeInterface</a></span>.
       </td>
      </tr>

      <tr>
       <td>7.1.0</td>
       <td>
        Il costruttore <span class="classname"><strong class="classname">DateTime</strong></span> ora include i
        microsecondi attuali nel valore costruito. Prima di questo, inizializzava
        sempre i microsecondi a <code class="literal">0</code>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 </div>

 






































































<h2>Indice dei contenuti</h2><ul class="chunklist chunklist_reference"><li><a href="datetime.add.php">DateTime::add</a> — Modifies a DateTime object, with added amount of days, months, years, hours, minutes and seconds</li><li><a href="datetime.construct.php">DateTime::__construct</a> — Returns new DateTime object</li><li><a href="datetime.createfromformat.php">DateTime::createFromFormat</a> — Parses a time string according to a specified format</li><li><a href="datetime.createfromimmutable.php">DateTime::createFromImmutable</a> — Returns new DateTime instance encapsulating the given DateTimeImmutable object</li><li><a href="datetime.createfrominterface.php">DateTime::createFromInterface</a> — Returns new DateTime object encapsulating the given DateTimeInterface object</li><li><a href="datetime.getlasterrors.php">DateTime::getLastErrors</a> — Alias di DateTimeImmutable::getLastErrors</li><li><a href="datetime.modify.php">DateTime::modify</a> — Alters the timestamp</li><li><a href="datetime.set-state.php">DateTime::__set_state</a> — The __set_state handler</li><li><a href="datetime.setdate.php">DateTime::setDate</a> — Sets the date</li><li><a href="datetime.setisodate.php">DateTime::setISODate</a> — Sets the ISO date</li><li><a href="datetime.settime.php">DateTime::setTime</a> — Sets the time</li><li><a href="datetime.settimestamp.php">DateTime::setTimestamp</a> — Sets the date and time based on an Unix timestamp</li><li><a href="datetime.settimezone.php">DateTime::setTimezone</a> — Sets the time zone for the DateTime object</li><li><a href="datetime.sub.php">DateTime::sub</a> — Subtracts an amount of days, months, years, hours, minutes and seconds from
   a DateTime object</li></ul>
</div>
<?php manual_footer($setup); ?>