<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.datetimeinterface.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'es',
  ),
  'this' => 
  array (
    0 => 'datetime.gettimestamp.php',
    1 => 'DateTimeInterface::getTimestamp',
    2 => 'Obtiene el timestamp Unix',
  ),
  'up' => 
  array (
    0 => 'class.datetimeinterface.php',
    1 => 'DateTimeInterface',
  ),
  'prev' => 
  array (
    0 => 'datetime.getoffset.php',
    1 => 'DateTimeInterface::getOffset',
  ),
  'next' => 
  array (
    0 => 'datetime.gettimezone.php',
    1 => 'DateTimeInterface::getTimezone',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'es',
    'path' => 'reference/datetime/datetimeinterface/gettimestamp.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="datetime.gettimestamp" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DateTimeInterface::getTimestamp</h1>
  <h1 class="refname">DateTimeImmutable::getTimestamp</h1>
  <h1 class="refname">DateTime::getTimestamp</h1>
  <h1 class="refname">date_timestamp_get</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">DateTimeInterface::getTimestamp</span> -- <span class="refname">DateTimeImmutable::getTimestamp</span> -- <span class="refname">DateTime::getTimestamp</span> -- <span class="refname">date_timestamp_get</span> &mdash; <span class="dc-title">Obtiene el timestamp Unix</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-datetime.gettimestamp-description">
  <h3 class="title">Descripción</h3>
  <p class="para">Estilo orientado a objetos</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>DateTimeInterface::getTimestamp</strong></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"><strong>DateTimeImmutable::getTimestamp</strong></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"><strong>DateTime::getTimestamp</strong></span>(): <span class="type"><a href="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">Estilo procedimental</p>
  <div class="methodsynopsis dc-description"><span class="methodname"><a href="function.date-timestamp-get.php" class="methodname">date_timestamp_get</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="language.types.integer.php" class="type int">int</a></span></div>

  <p class="para rdfs-comment">
   Obtiene el timestamp Unix.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-datetime.gettimestamp-parameters">
  <h3 class="title">Parámetros</h3>
  <p class="para">Esta función no contiene ningún parámetro.</p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-datetime.gettimestamp-returnvalues">
  <h3 class="title">Valores devueltos</h3>
  <p class="para">
   Devuelve el timestamp Unix que representa la fecha.
  </p>
 </div>


 <div class="refsect1 errors" id="refsect1-datetime.gettimestamp-errors">
  <h3 class="title">Errores/Excepciones</h3>
  <p class="para">
   Si el sello de tiempo no puede ser representado como un <span class="type"><a href="language.types.integer.php" class="type int">int</a></span>,
   se lanza una <span class="exceptionname"><a href="class.daterangeerror.php" class="exceptionname">DateRangeError</a></span>.
   Anterior a PHP 8.3.0, se lanzaba una <span class="exceptionname"><a href="class.valueerror.php" class="exceptionname">ValueError</a></span>.
   Y anterior a PHP 8.0.0, se devolvía <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en este caso.
   Sin embargo, el sello de tiempo puede ser obtenido como un <span class="type"><a href="language.types.string.php" class="type string">string</a></span> utilizando
   <span class="methodname"><a href="datetime.format.php" class="methodname">DateTimeInterface::format()</a></span> con el formato <code class="literal">U</code>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-datetime.gettimestamp-changelog">
  <h3 class="title">Historial de cambios</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Versión</th>
      <th>Descripción</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.3.0</td>
      <td>
       La excepción de fuera de rango ahora es una
       <span class="exceptionname"><a href="class.daterangeerror.php" class="exceptionname">DateRangeError</a></span>.
      </td>
     </tr>

     <tr>
      <td>8.0.0</td>
      <td>
       Estas funciones ya no devuelven <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> en caso de fallo.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-datetime.gettimestamp-examples">
  <h3 class="title">Ejemplos</h3>
  <div class="example" id="example-1">
   <p><strong>Ejemplo #1 Ejemplo con <span class="function"><strong>DateTime::getTimestamp()</strong></span></strong></p>
   <div class="example-contents"><p>Estilo orientado a objetos</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">();<br />echo </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getTimestamp</span><span style="color: #007700">();</span></span></code></div>
   </div>

   <div class="example-contents"><p>Resultado del ejemplo anterior es similar a:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">1272509157</pre>
</div>
   </div>
   <div class="example-contents"><p>Estilo procedimental</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= </span><span style="color: #0000BB">date_create</span><span style="color: #007700">();<br />echo </span><span style="color: #0000BB">date_timestamp_get</span><span style="color: #007700">(</span><span style="color: #0000BB">$date</span><span style="color: #007700">);</span></span></code></div>
   </div>

   <div class="example-contents"><p>Resultado del ejemplo anterior es similar a:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">1272509157</pre>
</div>
   </div>
  </div>
  <p class="para">
   Para obtener el sello de tiempo con precisión
   en milisegundos o microsegundos, es posible utilizar
   la función <span class="function"><a href="datetime.format.php" class="function">DateTimeInterface::format()</a></span>.
  </p>
  <div class="example" id="example-2">
   <p><strong>Ejemplo #2 Obtención del sello de tiempo con precisión en milisegundos y microsegundos</strong></p>
   <div class="example-contents"><p>Estilo orientado a objetos</p></div>
   <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br />$date </span><span style="color: #007700">= new </span><span style="color: #0000BB">DateTimeImmutable</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$milli </span><span style="color: #007700">= (int) </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Uv'</span><span style="color: #007700">); </span><span style="color: #FF8000">// Timestamp en milisegundos<br /></span><span style="color: #0000BB">$micro </span><span style="color: #007700">= (int) </span><span style="color: #0000BB">$date</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">format</span><span style="color: #007700">(</span><span style="color: #DD0000">'Uu'</span><span style="color: #007700">); </span><span style="color: #FF8000">// Timestamp en microsegundos<br /><br /></span><span style="color: #007700">echo </span><span style="color: #0000BB">$milli</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">, </span><span style="color: #0000BB">$micro</span><span style="color: #007700">, </span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;</span></span></code></div>
   </div>

   <div class="example-contents"><p>Resultado del ejemplo anterior es similar a:</p></div>
   <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">1674057635586
1674057635586918</pre>
</div>
   </div>
  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-datetime.gettimestamp-seealso">
  <h3 class="title">Ver también</h3>
  <ul class="simplelist">
   <li><span class="function"><a href="datetime.settimestamp.php" class="function" rel="rdfs-seeAlso">DateTime::setTimestamp()</a> - Establece la fecha y la hora bas&aacute;ndose en una marca temporal de Unix</span></li>
   <li><span class="function"><a href="datetimeimmutable.settimestamp.php" class="function" rel="rdfs-seeAlso">DateTimeImmutable::setTimestamp()</a> - Establece la fecha y hora basadas en una marca de tiempo Unix (Unix timestamp)</span></li>
   <li><span class="function"><a href="datetime.format.php" class="function" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - Retorna una fecha formateada seg&uacute;n el formato proporcionado</span></li>
  </ul>
 </div>


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