mirror of
https://github.com/php/doc-es.git
synced 2026-03-26 00:12:06 +01:00
269 lines
7.5 KiB
XML
269 lines
7.5 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
<!-- EN-Revision: 3a8c3e77df070a046c9d5b56b68926ca2d7e5ee3 Maintainer: PhilDaiguille Status: ready -->
|
|
<!-- Reviewed: no Maintainer: Marqitos -->
|
|
|
|
<refentry xml:id="function.date-parse-from-format" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>date_parse_from_format</refname>
|
|
<refpurpose>Recupera las informaciones de una fecha dada siguiendo un formato específico</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<type>array</type><methodname>date_parse_from_format</methodname>
|
|
<methodparam><type>string</type><parameter>format</parameter></methodparam>
|
|
<methodparam><type>string</type><parameter>datetime</parameter></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Devuelve un array asociativo que contiene informaciones
|
|
detalladas sobre una fecha/hora dada.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<para>
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>format</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Documentación sobre el uso del <parameter>format</parameter>,
|
|
por favor referirse a la documentación de
|
|
<function>DateTimeImmutable::createFromFormat</function>. Las
|
|
mismas reglas se aplican.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>datetime</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Cadena que representa la fecha/hora.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<!-- See also &return.success; -->
|
|
<para>
|
|
Devuelve un array asociativo con informaciones detalladas
|
|
sobre la fecha/hora dada.
|
|
</para>
|
|
<para>
|
|
El array devuelto tiene claves para <literal>year</literal>,
|
|
<literal>month</literal>, <literal>day</literal>, <literal>hour</literal>,
|
|
<literal>minute</literal>, <literal>second</literal>,
|
|
<literal>fraction</literal>, y <literal>is_localtime</literal>.
|
|
</para>
|
|
<para>
|
|
Si <literal>is_localtime</literal> está presente, entonces
|
|
<literal>zone_type</literal> indica el tipo de zona horaria. Para el tipo
|
|
<literal>1</literal> (desplazamiento UTC) se añaden los campos
|
|
<literal>zone</literal> y <literal>is_dst</literal>. Para el tipo
|
|
<literal>2</literal> (abreviatura) se añaden los campos
|
|
<literal>tz_abbr</literal> y <literal>is_dst</literal>. Para el tipo
|
|
<literal>3</literal> (identificador de zona horaria) se añaden los campos
|
|
<literal>tz_abbr</literal> y <literal>tz_id</literal>.
|
|
</para>
|
|
<para>
|
|
El array incluye los campos <literal>warning_count</literal> y
|
|
<literal>warnings</literal>. El primero indica el número
|
|
de advertencias. Las claves del array <literal>warnings</literal>
|
|
indican la posición en el parámetro <parameter>datetime</parameter>
|
|
donde ocurrió la advertencia, con el valor de cadena que describe
|
|
la advertencia misma. Un ejemplo a continuación muestra tal advertencia.
|
|
</para>
|
|
<para>
|
|
El array incluye también los campos <literal>error_count</literal> y
|
|
<literal>errors</literal>. El primero indica el número
|
|
de errores. Las claves del array <literal>errors</literal> indican
|
|
la posición en el parámetro <parameter>datetime</parameter> donde ocurrió el error,
|
|
con el valor de cadena que describe la advertencia misma. Un ejemplo a continuación muestra tal advertencia.
|
|
</para>
|
|
<warning>
|
|
<para>
|
|
El número de elementos de array en los arrays <literal>warnings</literal> y
|
|
<literal>errors</literal> puede ser inferior a <literal>warning_count</literal>
|
|
o <literal>error_count</literal> si ocurrieron en la misma posición.
|
|
</para>
|
|
</warning>
|
|
</refsect1>
|
|
|
|
<refsect1 role="errors">
|
|
&reftitle.errors;
|
|
<para>
|
|
Esta función lanza una <exceptionname>ValueError</exceptionname> cuando el
|
|
<parameter>datetime</parameter> contiene bytes NULL.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="changelog">
|
|
&reftitle.changelog;
|
|
<informaltable>
|
|
<tgroup cols="2">
|
|
<thead>
|
|
<row>
|
|
<entry>&Version;</entry>
|
|
<entry>&Description;</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>8.0.21, 8.1.8, 8.2.0</entry>
|
|
<entry>
|
|
Ahora lanza una <exceptionname>ValueError</exceptionname> cuando se pasan bytes NULL
|
|
en <parameter>datetime</parameter>, lo cual antes era ignorado silenciosamente.
|
|
</entry>
|
|
</row>
|
|
<row>
|
|
<entry>7.2.0</entry>
|
|
<entry>
|
|
El elemento <literal>zone</literal> del array devuelto representa segundos
|
|
en lugar de minutos ahora, y su signo es invertido. Por ejemplo
|
|
<literal>-120</literal> ahora es igual a <literal>7200</literal>.
|
|
</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<para>
|
|
<example>
|
|
<title>Ejemplo con <function>date_parse_from_format</function></title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$date = "6.1.2009 13:00+01:00";
|
|
print_r(date_parse_from_format("j.n.Y H:iP", $date));
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Array
|
|
(
|
|
[year] => 2009
|
|
[month] => 1
|
|
[day] => 6
|
|
[hour] => 13
|
|
[minute] => 0
|
|
[second] => 0
|
|
[fraction] => 0
|
|
[warning_count] => 0
|
|
[warnings] => Array
|
|
(
|
|
)
|
|
|
|
[error_count] => 0
|
|
[errors] => Array
|
|
(
|
|
)
|
|
|
|
[is_localtime] => 1
|
|
[zone_type] => 1
|
|
[zone] => 3600
|
|
[is_dst] =>
|
|
)
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
<para>
|
|
<example>
|
|
<title>
|
|
Ejemplo de <function>date_parse_from_format</function>
|
|
con advertencias
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$date = "26 August 2022 22:30 pm";
|
|
$parsed = date_parse_from_format("j F Y G:i a", $date);
|
|
|
|
echo "Warnings count: ", $parsed['warning_count'], "\n";
|
|
foreach ($parsed['warnings'] as $position => $message) {
|
|
echo "\tOn position {$position}: {$message}\n";
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Warnings count: 1
|
|
On position 23: The parsed time was invalid
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
|
|
<para>
|
|
<example>
|
|
<title>
|
|
Ejemplo de <function>date_parse_from_format</function>
|
|
con errores
|
|
</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
$date = "26 August 2022 CEST";
|
|
$parsed = date_parse_from_format("j F Y H:i", $date);
|
|
|
|
echo "Errors count: ", $parsed['error_count'], "\n";
|
|
foreach ($parsed['errors'] as $position => $message) {
|
|
echo "\tOn position {$position}: {$message}\n";
|
|
}
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs;
|
|
<screen>
|
|
<![CDATA[
|
|
Errors count: 3
|
|
On position 15: A two digit hour could not be found
|
|
On position 19: Not enough data available to satisfy format
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</para>
|
|
</refsect1>
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<para>
|
|
<simplelist>
|
|
<member><function>DateTimeImmutable::createFromFormat</function></member>
|
|
<member><function>checkdate</function></member>
|
|
</simplelist>
|
|
</para>
|
|
</refsect1>
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|