<?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.strtotime.php',
    1 => 'strtotime',
    2 => 'Transforme un texte anglais en timestamp',
  ),
  'up' => 
  array (
    0 => 'ref.datetime.php',
    1 => 'Fonctions Date/Heure',
  ),
  'prev' => 
  array (
    0 => 'function.strptime.php',
    1 => 'strptime',
  ),
  'next' => 
  array (
    0 => 'function.time.php',
    1 => 'time',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'fr',
    'path' => 'reference/datetime/functions/strtotime.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

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

 </div>
 <div class="refsect1 description" id="refsect1-function.strtotime-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>strtotime</strong></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="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$baseTimestamp</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="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   La fonction <span class="function"><strong>strtotime()</strong></span> essaye de lire une
   date au format anglais fournie par le paramètre <code class="parameter">time</code>,
   et de la transformer en timestamp Unix (le nombre de secondes depuis
   le 1er Janvier 1970 à 00:00:00 UTC), relativement au timestamp
   <code class="parameter">baseTimestamp</code>, ou à la date courante si ce dernier
   est omis. L&#039;analyse de la chaîne de date est définie dans 
   <a href="datetime.formats.php" class="link">les formats de date et d&#039;heure</a> 
   et comporte plusieurs considérations subtiles. Il est fortement recommandé 
   d&#039;en examiner tous les détails.
  </p>
  <div class="warning"><strong class="warning">Avertissement</strong>
   <p class="para">
    L&#039;horodatage Unix que cette fonction retourne ne contient pas d&#039;information
    à propos des fuseaux horaires. Pour faire des calculs avec les informations
    de date/moment, il est recommandé d&#039;utiliser
    <span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span> qui est plus capable.
   </p>
  </div>
  <p class="para">
   Chaque paramètre de la fonction utilise le décalage horaire par défaut
   à moins qu&#039;un décalage horaire y soit explicitement paramétré.
   Il faut veiller à ne pas utiliser un décalage horaire différent pour
   chaque paramètre à moins que ce soit ce dont il est nécessaire.
   Se reporter à la fonction <span class="function"><a href="function.date-default-timezone-get.php" class="function">date_default_timezone_get()</a></span>
   afin de savoir comment définir un décalage horaire par défaut.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.strtotime-parameters">
  <h3 class="title">Liste de paramètres</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">datetime</code></dt>
     <dd>
       <p class="para">Une chaîne date/heure. Les formats valides sont expliqués dans la documentation sur les
<a href="datetime.formats.php" class="link">formats Date et Heure</a>.</p>
     </dd>
    
    
     <dt><code class="parameter">baseTimestamp</code></dt>
     <dd>
      <p class="para">
       Le timestamp, représentant la date courante, utilisé pour le calcul
       relatif des dates.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.strtotime-returnvalues">
  <h3 class="title">Valeurs de retour</h3>
  <p class="para">
   Retourne un timestamp en cas de succès, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> sinon.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-function.strtotime-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.strtotime-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">baseTimestamp</code> est désormais nullable.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.strtotime-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>strtotime()</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: #007700">echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"now"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"10 September 2000"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"+1 day"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"+1 week"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"+1 week 2 days 4 hours 2 seconds"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"next Thursday"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />echo </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #DD0000">"last Monday"</span><span style="color: #007700">), </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</span></span></code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-2">
    <p><strong>Exemple #2 Vérification d&#039;erreur</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$str </span><span style="color: #007700">= </span><span style="color: #DD0000">'Pas bon'</span><span style="color: #007700">;<br /><br />if ((</span><span style="color: #0000BB">$timestamp </span><span style="color: #007700">= </span><span style="color: #0000BB">strtotime</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">)) === </span><span style="color: #0000BB">false</span><span style="color: #007700">) {<br />   echo </span><span style="color: #DD0000">"La chaîne (</span><span style="color: #0000BB">$str</span><span style="color: #DD0000">) est boguée"</span><span style="color: #007700">;<br />} else {<br />   echo </span><span style="color: #DD0000">"</span><span style="color: #0000BB">$str</span><span style="color: #DD0000"> == " </span><span style="color: #007700">. </span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">'l dS \o\f F Y h:i:s A'</span><span style="color: #007700">, </span><span style="color: #0000BB">$timestamp</span><span style="color: #007700">);<br />}</span></span></code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.strtotime-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Dans ce cas, la date &quot;relative&quot; signifie également que si un composant 
    particulier de l&#039;horodatage n&#039;est pas fourni, il sera extrait textuellement de 
    <code class="parameter">baseTimestamp</code>. Autrement dit, 
    <code class="code">strtotime(&#039;February&#039;)</code>, s&#039;il est exécuté le 31 mai 2022, sera 
    interprété comme le <code class="literal">31 février 2022</code>, qui débordera sur 
    un horodatage le <code class="literal">3 mars</code>. (Dans une année bissextile, 
    ce serait le <code class="literal">2 mars</code>.) L&#039;utilisation de 
    <code class="code">strtotime(&#039;1 February&#039;)</code> ou <code class="code">strtotime(&#039;first day of February&#039;)</code>
    éviterait ce problème.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    Si le chiffre des années est précisé sur deux chiffres, les valeurs entre
    00-69 correspondent à 2000-2069 et 70-99 à 1970-1999. Voir les notes ci-après
    concernant les différences possibles entre systèmes 32-bit (des dates peuvent
    échouer après le 19/01/2038 à 03:14:07).
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    L&#039;intervalle de validité d&#039;un timestamp va du 
    Vendredi 13 Décembre 1901 20:45:54 UTC au Mardi 19 Janvier 2038 03:14:07 UTC.
    (Cela correspond aux dates maximales et minimales pour un
    entier de 32 bits signé).
   </p>
   <p class="para">
    Pour les versions 64-bit de PHP, l&#039;intervalle valide d&#039;un timestamp
    est réellement infini, sachant que 64 bits peut représenter approximativement
    293 milliards d&#039;années dans n&#039;importe quelle direction.
   </p>
  </p></blockquote>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    L&#039;utilisation de cette fonction sur des opérations mathématiques
    n&#039;est pas conseillée. Il vaut mieux utiliser dans ce cas
    <span class="methodname"><a href="datetime.add.php" class="methodname">DateTime::add()</a></span> et <span class="methodname"><a href="datetime.sub.php" class="methodname">DateTime::sub()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.strtotime-seealso">
  <h3 class="title">Voir aussi</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="classname"><a href="class.datetimeimmutable.php" class="classname">DateTimeImmutable</a></span></li>
    <li><span class="methodname"><a href="datetimeimmutable.createfromformat.php" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::createFromFormat()</a> - Analyse une heure au format texte selon le format sp&eacute;cifi&eacute;.</span></li>
    <li><a href="datetime.formats.php" class="link">Les formats sur les dates</a></li>
    <li><span class="function"><a href="function.checkdate.php" class="function" rel="rdfs-seeAlso">checkdate()</a> - Valide une date gr&eacute;gorienne</span></li>
    <li><span class="function"><a href="function.strptime.php" class="function" rel="rdfs-seeAlso">strptime()</a> - Analyse une date g&eacute;n&eacute;r&eacute;e par strftime</span></li>
   </ul>
  </p>
 </div>

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