<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.datetime.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'it',
  ),
  'this' => 
  array (
    0 => 'function.date.php',
    1 => 'date',
    2 => 'Formatta un timestamp Unix',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Date/Time Funzioni',
  ),
  'prev' => 
  array (
    0 => 'function.checkdate.php',
    1 => 'checkdate',
  ),
  'next' => 
  array (
    0 => 'function.date-add.php',
    1 => 'date_add',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'it',
    'path' => 'reference/datetime/functions/date.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.date" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">date</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">date</span> &mdash; <span class="dc-title">Formatta un timestamp Unix</span></p>

 </div>
  
 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">Descrizione</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>date</strong></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"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$timestamp</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.string.php" class="type string">string</a></span></div>

  <p class="para rdfs-comment">
   Restituisce una stringa formattata in accordo con il formato della stringa data usando
   l&#039;intero <code class="parameter">timestamp</code> dato (timestamp Unix) o l&#039;orario corrente
   se nessun timestamp è dato. In altre parole, <code class="parameter">timestamp</code>
   è opzionale e di default prende il valore di <span class="function"><a href="function.time.php" class="function">time()</a></span>.
  </p>
  <div class="warning"><strong class="warning">Avviso</strong>
   <p class="para">
    I timestamp Unix non gestiscono i fusi orari. Utilizzare la
    classe <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span>, e i suoi
    metodi di formattazione <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> per
    formattare le informazioni data/ora con un fuso orario allegato.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">Elenco dei parametri</h3>
  <dl>
   
    <dt><code class="parameter">format</code></dt>
    <dd>
     <p class="para">
      Formato accettato da <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span>.
     </p>
    </dd>
   

   
<dt><code class="parameter">timestamp</code></dt><dd><p class="para">
Il parametro opzionale <code class="parameter">timestamp</code> è un 
<span class="type"><a href="language.types.integer.php" class="type integer">integer</a></span> timestamp Unix che ha come default
l&#039;ora locale attuale se un <code class="parameter">timestamp</code> non è fornito. In altre 
parole, ha come default il valore di <span class="function"><a href="function.time.php" class="function">time()</a></span>. 
</p></dd>

  </dl>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.date-returnvalues">
  <h3 class="title">Valori restituiti</h3>
  <p class="para">
   Restituisce una stringa data formattata. Se viene utilizzato un valore non numerico per 
   <code class="parameter">timestamp</code>, viene restituito <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> e viene 
   emesso un errore di livello <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-errors">
  <h3 class="title">Errori/Eccezioni</h3>

   <p class="para">
Ogni chiamata a una funzione data/ora genera un <strong><code><a href="errorfunc.constants.php#constant.e-notice">E_NOTICE</a></code></strong> 
se il time zone non è valido, e/o un messaggio <strong><code><a href="errorfunc.constants.php#constant.e-strict">E_STRICT</a></code></strong>
o <strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong>
se si usano le impostazioni di sistema o la variabile d&#039;ambiente <var class="varname">TZ</var>.
Vedere anche <span class="function"><a href="function.date-default-timezone-set.php" class="function">date_default_timezone_set()</a></span></p>

 </div>


 <div class="refsect1 changelog" id="refsect1-function.date-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.0.0</td>
       <td>
        <code class="parameter">timestamp</code> ora è nullable.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-examples">
  <h3 class="title">Esempi</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Esempi di <span class="function"><strong>date()</strong></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">// imposta il fuso orario di default da utilizzare.<br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">'UTC'</span><span style="color: #007700">);<br /><br /><br /></span><span style="color: #FF8000">// Stampa qualcosa di simile a: Monday<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Stampa qualcosa di simile a: Monday 8th of August 2005 03:12:46 PM<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l jS \of F Y h:i:s A'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Stampa: July 1, 2000 is on a Saturday<br /></span><span style="color: #007700">echo </span><span style="color: #DD0000">"July 1, 2000 is on a " </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"l"</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">/* usa le costanti nel parametro format */<br />// stampa qualcosa di simile a: Wed, 25 Sep 2013 15:28:57 -0700<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_RFC2822</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// stampa qualcosa di simile a: 2000-07-01T00:00:00+00:00<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #0000BB">DATE_ATOM</span><span style="color: #007700">, </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">7</span><span style="color: #007700">, </span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">2000</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   È possibile evitare che un carattere riconosciuto nella stringa formato venga
   espanso effettuando l&#039;escape di esso anteponendo un backslash. Se il carattere con
   un backslash è già una sequenza speciale, potrebbe essere necessario effettuare l&#039;escape anche
   del backslash.
   <div class="example" id="example-2">
    <p><strong>Example #2 Effettuare l&#039;escape dei caratteri in <span class="function"><strong>date()</strong></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">// stampa qualcosa di simile a: Wednesday the 15th<br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l \t\h\e jS'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   È possibile utilizzare insieme <span class="function"><strong>date()</strong></span> e
   <span class="function"><a href="function.mktime.php" class="function">mktime()</a></span> per trovare date nel futuro
   o nel passato.
   <div class="example" id="example-3">
    <p><strong>Example #3 Esempio di <span class="function"><strong>date()</strong></span> e di <span class="function"><a href="function.mktime.php" class="function">mktime()</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 />$tomorrow  </span><span style="color: #007700">= </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)  , </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$lastmonth </span><span style="color: #007700">= </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">)-</span><span style="color: #0000BB">1</span><span style="color: #007700">, </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),   </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">$nextyear  </span><span style="color: #007700">= </span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">, </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m"</span><span style="color: #007700">),   </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"d"</span><span style="color: #007700">),   </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y"</span><span style="color: #007700">)+</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
   <blockquote class="note"><p><strong class="note">Nota</strong>: 
    <p class="para">
     Questo può essere più affidabile rispetto che semplicemente aggiungere o sottrarre il numero
     di secondi in un giorno o in un mese ad un timestamp a causa dell&#039;ora
     legale.
    </p>
   </p></blockquote>
  </p>
  <p class="para">
   Alcuni esempi della formattazione <span class="function"><strong>date()</strong></span>. Notare che
   si dovrebbe effettuare l&#039;escape di qualsiasi altro carattere, come tutti quelli che
   attualmente hanno un significato speciale produrranno risultati indesiderati, e
   ad altri caratteri potrebbe essere assegnato un significato nelle versioni future di PHP.
   Quando si effettua l&#039;escape, assicurarsi di usare gli apici singoli in modo da evitare che i caratteri
   come \n divengano nuove linee.
   <div class="example" id="example-4">
    <p><strong>Example #4 Formattazione di <span class="function"><strong>date()</strong></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">// Assumendo che oggi sia Il 10 Marzo, 2001, 5:16:18 pm, e che noi siamo nel<br />// Fuso Orario Mountain Standard Time (MST)<br /><br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"F j, Y, g:i a"</span><span style="color: #007700">);                 </span><span style="color: #FF8000">// March 10, 2001, 5:16 pm<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"m.d.y"</span><span style="color: #007700">);                         </span><span style="color: #FF8000">// 03.10.01<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"j, n, Y"</span><span style="color: #007700">);                       </span><span style="color: #FF8000">// 10, 3, 2001<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Ymd"</span><span style="color: #007700">);                           </span><span style="color: #FF8000">// 20010310<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'h-i-s, j-m-y, it is w Day'</span><span style="color: #007700">);     </span><span style="color: #FF8000">// 05-16-18, 10-03-01, 1631 1618 6 Satpm01<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'\i\t \i\s \t\h\e jS \d\a\y.'</span><span style="color: #007700">);   </span><span style="color: #FF8000">// it is the 10th day.<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"D M j G:i:s T Y"</span><span style="color: #007700">);               </span><span style="color: #FF8000">// Sat Mar 10 17:16:18 MST 2001<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'H:m:s \m \i\s\ \m\o\n\t\h'</span><span style="color: #007700">);     </span><span style="color: #FF8000">// 17:03:18 m is month<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"H:i:s"</span><span style="color: #007700">);                         </span><span style="color: #FF8000">// 17:16:18<br /></span><span style="color: #0000BB">$today </span><span style="color: #007700">= </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"Y-m-d H:i:s"</span><span style="color: #007700">);                   </span><span style="color: #FF8000">// 2001-03-10 17:16:18 (the MySQL DATETIME format)<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Per formattare le date in altri lingue,
   può essere utilizzata <span class="methodname"><a href="intldateformatter.format.php" class="methodname">IntlDateFormatter::format()</a></span>
   al posto di <span class="function"><strong>date()</strong></span>.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.date-notes">
  <h3 class="title">Note</h3>
  <blockquote class="note"><p><strong class="note">Nota</strong>: 
   <p class="para">
    Per generare un timestamp da una stringa che rappresenta la data, si
    può essere in grado di utilizzare <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span>. Inoltre, alcuni
    database hanno delle funzioni per convertire i loro formati data in timestamp
    (come la funzione <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP</a>
    di MySQL).
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">Suggerimento</strong>
   <p class="para">
    Il timestamp dell&#039;inizio della richiesta è disponibile in
    <var class="varname"><a href="reserved.variables.server.php" class="classname">$_SERVER['REQUEST_TIME']</a></var>.
   </p>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.date-seealso">
  <h3 class="title">Vedere anche:</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="datetimeimmutable.construct.php" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::__construct()</a> - Returns new DateTimeImmutable object</span></li>
    <li><span class="methodname"><a href="datetime.format.php" class="methodname" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - Returns date formatted according to given format</span></li>
    <li><span class="function"><a href="function.gmdate.php" class="function" rel="rdfs-seeAlso">gmdate()</a> - Formatta una data/ora GMT/UTC</span></li>
    <li><span class="function"><a href="function.idate.php" class="function" rel="rdfs-seeAlso">idate()</a> - Format a local time/date part as integer</span></li>
    <li><span class="function"><a href="function.getdate.php" class="function" rel="rdfs-seeAlso">getdate()</a> - Restituisce informazioni sulla data/orario</span></li>
    <li><span class="function"><a href="function.getlastmod.php" class="function" rel="rdfs-seeAlso">getlastmod()</a> - Restituisce la data dell'ultima modifica alla pagina</span></li>
    <li><span class="function"><a href="function.mktime.php" class="function" rel="rdfs-seeAlso">mktime()</a> - Restituisce il timestamp Unix per una data</span></li>
    <li><span class="methodname"><a href="intldateformatter.format.php" class="methodname" rel="rdfs-seeAlso">IntlDateFormatter::format()</a> - Format the date/time value as a string</span></li>
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Restituisce l'attuale UNIX timestamp</span></li>
    <li><a href="class.datetimeinterface.php#datetimeinterface.constants.types" class="link">Costanti di DateTime Predefinite</a></li>
   </ul>
  </p>
 </div>

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