<?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 => 'fr',
  ),
  'this' => 
  array (
    0 => 'function.date.php',
    1 => 'date',
    2 => 'Formate un horodatage Unix',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Fonctions Date/Heure',
  ),
  'prev' => 
  array (
    0 => 'function.checkdate.php',
    1 => 'checkdate',
  ),
  'next' => 
  array (
    0 => 'function.date-add.php',
    1 => 'date_add',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    '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">Formate un horodatage Unix</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.date-description">
  <h3 class="title">Description</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">
   Retourne une date sous forme d&#039;une chaîne, au format
   donné par le paramètre <code class="parameter">format</code>,
   fournie par le paramètre <code class="parameter">timestamp</code> (horodatage Unix)
   ou la date et l&#039;heure courantes si aucun timestamp n&#039;est fourni.
   En d&#039;autres termes, le paramètre <code class="parameter">timestamp</code>
   est optionnel et vaut par défaut la valeur de la fonction <span class="function"><a href="function.time.php" class="function">time()</a></span>.
  </p>
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="para">
    Les horodatages Unix ne gèrent pas les fuseaux horaires. Utiliser
    la classe <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span>, et sa méthode de 
    formatage <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> pour 
    formater les informations de date/heure avec un fuseau horaire attaché.
   </p>
  </div>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.date-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <dl>
   
    <dt><code class="parameter">format</code></dt>
    <dd>
     <p class="para">
      Format accepté par <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span>.
     </p>
     <blockquote class="note"><p><strong class="note">Note</strong>: 
      <span class="simpara">
       <span class="function"><strong>date()</strong></span> générera toujours
       <code class="literal">000000</code> pour les microsecondes puisqu&#039;il prend un 
       paramètre <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>, alors que <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span>
       prend en charge les microsecondes si un objet de type <span class="interfacename"><a href="class.datetimeinterface.php" class="interfacename">DateTimeInterface</a></span>
       a été créé avec des microsecondes.
      </span>
     </p></blockquote>
    </dd>
   
    
   
<dt><code class="parameter">timestamp</code></dt><dd><p class="para">
    Le paramètre optionnel <code class="parameter">timestamp</code> est un timestamp
    Unix de type <a href="language.types.integer.php" class="link">entier</a> qui vaut par défaut l&#039;heure courante locale si
    <code class="parameter">timestamp</code> est omis ou <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>. En d&#039;autres
    termes, il vaut par défaut la valeur de la fonction <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">Valeurs de retour</h3>
  <p class="para">
   Retourne une date formatée en chaîne de caractères.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.date-errors">
  <h3 class="title">Erreurs / Exceptions</h3>
  <p class="para">
Chaque appel à une fonction date/heure générera un diagnostic de type
<strong><code><a href="errorfunc.constants.php#constant.e-warning">E_WARNING</a></code></strong> si le fuseau horaire n&#039;est pas valide.
Voir aussi <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">Historique</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>Version</th>
       <th>Description</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        <code class="parameter">timestamp</code> est désormais nullable.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.date-examples">
  <h3 class="title">Exemples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Exemple #1 Exemple avec <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">// Définit le fuseau horaire par défaut à utiliser.<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">// Affichage de quelque chose comme : 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">). </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Affichage de quelque chose comme : 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">). </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Affiche : 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">)). </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">/* utilise les constantes dans le paramètre format */<br />// Affichage de quelque chose comme : 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">). </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">// Affichage de quelque chose comme : 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">));</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Il est possible de faire afficher un caractère spécial dans la chaîne de format
   en le protégeant par un antislash. Si le caractère est lui-même une séquence
   incluant un antislash, on devra protéger aussi l&#039;antislash.
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Protection des caractères dans la fonction <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">// Affichage de quelque chose comme : 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">);</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   Voici maintenant quelques exemples de formatage avec
   <span class="function"><strong>date()</strong></span>. Il est à noter qu&#039;il est recommandé d&#039;échapper tous
   les autres caractères, car s&#039;ils ont une signification
   spéciale, ils risquent de produire des effets secondaires
   indésirables. Il est à noter que les versions futures de PHP
   peuvent attribuer une signification à des lettres qui sont
   actuellement inertes. Lorsque l&#039;on échappe les caractères,
   pensez à utiliser des guillemets simples, pour que les
   séquences <code class="literal">\n</code> ne deviennent pas des
   nouvelles lignes.
   <div class="example" id="example-3">
    <p><strong>Exemple #3 Exemple avec <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">// Aujourd'hui, le 10 Mars 2001, 5:16:18 pm, Fuseau horaire <br />// Mountain Standard Time (MST)<br /> <br /></span><span style="color: #0000BB">date_default_timezone_set</span><span style="color: #007700">(</span><span style="color: #DD0000">"America/Phoenix"</span><span style="color: #007700">);<br /><br />echo </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: #DD0000">"\n"</span><span style="color: #007700">;                 </span><span style="color: #FF8000">// March 10, 2001, 5:16 pm<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 03.10.01<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;                       </span><span style="color: #FF8000">// 10, 3, 2001<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;                           </span><span style="color: #FF8000">// 20010310<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</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: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;   </span><span style="color: #FF8000">// it is the 10th day.<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;               </span><span style="color: #FF8000">// Sat Mar 10 17:16:18 MST 2001<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;     </span><span style="color: #FF8000">// 17:03:18 m is month<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</span><span style="color: #007700">;                         </span><span style="color: #FF8000">// 17:16:18<br /></span><span style="color: #007700">echo </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: #DD0000">"\n"</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">
   Pour formater des dates dans d&#039;autres langues,
   <span class="methodname"><a href="intldateformatter.format.php" class="methodname">IntlDateFormatter::format()</a></span>
   peut être utilisé à la place de <span class="function"><strong>date()</strong></span>.
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.date-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Pour générer un timestamp à partir d&#039;une représentation de date,
    il est possible d&#039;utiliser la fonction <span class="function"><a href="function.strtotime.php" class="function">strtotime()</a></span>. De plus,
    certaines bases de données disposent de fonctions pour convertir leurs
    propres formats de date en timestamp (par exemple,
    MySQL et sa fonction <a href="http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html" class="link external">&raquo;&nbsp;UNIX_TIMESTAMP()</a>).
   </p>
  </p></blockquote>
  <div class="tip"><strong class="tip">Astuce</strong>
   <p class="para">
    Un timestamp représentant le début de la requête est disponible dans la
    variable <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">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="methodname"><a href="datetimeimmutable.construct.php" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::__construct()</a> - Retourne un nouvel objet DateTimeImmutable</span></li>
    <li><span class="methodname"><a href="datetime.format.php" class="methodname" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - Retourne une date format&eacute;e suivant le format fourni</span></li>
    <li><span class="function"><a href="function.gmdate.php" class="function" rel="rdfs-seeAlso">gmdate()</a> - Formate une date/heure GMT/TUC</span></li>
    <li><span class="function"><a href="function.idate.php" class="function" rel="rdfs-seeAlso">idate()</a> - Formate une partie de l'heure/date locale en tant qu'entier</span></li>
    <li><span class="function"><a href="function.getdate.php" class="function" rel="rdfs-seeAlso">getdate()</a> - Retourne la date/heure</span></li>
    <li><span class="function"><a href="function.getlastmod.php" class="function" rel="rdfs-seeAlso">getlastmod()</a> - Retourne la date de derni&egrave;re modification de la page</span></li>
    <li><span class="function"><a href="function.mktime.php" class="function" rel="rdfs-seeAlso">mktime()</a> - Retourne l'horodatage UNIX d'une date</span></li>
    <li><span class="methodname"><a href="intldateformatter.format.php" class="methodname" rel="rdfs-seeAlso">IntlDateFormatter::format()</a> - Formate la date et l'heure sous forme de cha&icirc;ne</span></li>
    <li><span class="function"><a href="function.time.php" class="function" rel="rdfs-seeAlso">time()</a> - Retourne l'horodatage UNIX actuel</span></li>
    <li><a href="class.datetimeinterface.php#datetimeinterface.constants.types" class="link">Constantes DateTime prédéfinies</a></li>
   </ul>
  </p>
 </div>

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