| STRPTIME(3) | Manual del Programador de Linux | STRPTIME(3) |
strptime - convierte una cadena de caracteres que representa un tiempo a una estructura tm
#define _XOPEN_SOURCE /* Vea feature_test_macros(7) */
#include <time.h>
char *strptime(const char *s, const char *format, struct tm *tm);
The strptime() function is the converse of strftime(3); it converts the character string pointed to by s to values which are stored in the "broken-down time" structure pointed to by tm, using the format specified by format.
La estructura de tiempo descompuesto tm se define en <time.h> como sigue:
struct tm {
int tm_sec; /* Seconds (0-60) */
int tm_min; /* Minutes (0-59) */
int tm_hour; /* Hours (0-23) */
int tm_mday; /* Day of the month (1-31) */
int tm_mon; /* Month (0-11) */
int tm_year; /* Year - 1900 */
int tm_wday; /* Day of the week (0-6, Sunday = 0) */
int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
int tm_isdst; /* Daylight saving time */
};
For more details on the tm structure, see ctime(3).
The format argument is a character string that consists of field descriptors and text characters, reminiscent of scanf(3). Each field descriptor consists of a % character followed by another character that specifies the replacement for the field descriptor. All other characters in the format string must have a matching character in the input string, except for whitespace, which matches zero or more whitespace characters in the input string. There should be whitespace or other alphanumeric characters between any two field descriptors.
La función strptime() procesa la cadena de entrada de izquierda a derecha. Cada uno de los tres posibles elementos de entrada (espacio en blanco, literal o formato) se tratan uno detrás de otro. Si no se puede hacer coincidir la entrada con la cadena de formato, la función se detiene. El resto de las cadenas de formato y de entrada no se procesa.
The supported input field descriptors are listed below. In case a text string (such as the name of a day of the week or a month name) is to be matched, the comparison is case insensitive. In case a number is to be matched, leading zeros are permitted but not required.
Algunos descriptores de campo pueden ser modificados por los caracteres modificadores E u O para indicar el uso de un formato o especificación alternativo. Si el formato o especificación alternativo no existe en la localización actual, se utiliza el descriptor de campo sin modificar.
El modificador E especifica que la cadena de entrada puede contener versiones alternativas de la representación de fecha y hora dependientes de la localización:
El modificador O especifica que la entrada numérica puede estar en un formato alternativo dependiente de la localización:
The return value of the function is a pointer to the first character not processed in this function call. In case the input string contains more characters than required by the format string, the return value points right after the last consumed input character. In case the whole input string is consumed, the return value points to the null byte at the end of the string. If strptime() fails to match all of the format string and therefore an error occurred, the function returns NULL.
Para obtener una explicación de los términos usados en esta sección, véase attributes(7).
| Interfaz | Atributo | Valor |
| strptime() | Seguridad del hilo | MT-Safe env locale |
POSIX.1-2001, POSIX.1-2008, SUSv2.
In principle, this function does not initialize tm but stores only the values specified. This means that tm should be initialized before the call. Details differ a bit between different UNIX systems. The glibc implementation does not touch those fields which are not explicitly specified, except that it recomputes the tm_wday and tm_yday field if any of the year, month, or day elements changed.
The 'y' (year in century) specification is taken to specify a year in the range 1950–2049 by glibc 2.0. It is taken to be a year in 1969–2068 since glibc 2.1.
Por razones de simetría, glibc trata de dar soporte en strptime() a los mismos caracteres de formato que para strftime(3). (En la mayoría de casos se analizan los campos correspondientes, pero no se modifica ningún campo de la estructura tm.) Esto conduce a
Similarly, because of GNU extensions to strftime(3), %k is accepted as a synonym for %H, and %l should be accepted as a synonym for %I, and %P is accepted as a synonym for %p. Finally
The glibc implementation does not require whitespace between two field descriptors.
El siguiente ejemplo demuestra el uso de strptime() y strftime(3).
#define _XOPEN_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
int
main(void)
{
struct tm tm;
char buf[255];
memset(&tm, 0, sizeof(tm));
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
puts(buf);
exit(EXIT_SUCCESS);
}
Esta página es parte de la versión 5.10 del proyecto Linux man-pages. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en https://www.kernel.org/doc/man-pages/.
La traducción al español de esta página del manual fue creada por Gerardo Aburruzaga García <gerardo.aburruzaga@uca.es>, Juan Piernas <piernas@ditec.um.es> y Miguel Pérez Ibars <mpi79470@alu.um.es>
Esta traducción es documentación libre; lea la GNU General Public License Version 3 o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD.
Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a debian-l10n-spanish@lists.debian.org>..
| 1 Noviembre 2020 | GNU |