STRPTIME (3)
convert a string representation of time to a time tm structure
SYNOPSIS
#include <time.h>
char *strptime(const char * s , const char * format ,
struct tm * tm );
DESCRIPTION
"strptime function" "" "\fLstrptime()\fP \(em date and time conversion"
strptime(\|)
is the complementary function to
strftime(\|)
and converts the character string pointed to by
s
to a time value, which is stored in the
tm
structure pointed to by
tm ,
using the format specified by
format .
format
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. Exceptions
are white spaces in the format string which can match zero or more
white space characters in the input string.
The strptime() function processes the input string from right to
left. Each of the three possible input elements (white space,
literal, or format) are handled one after the other. If the input
cannot be matched to the format string the function stops. The
remainder of the format and input strings are not processed.
The following field descriptors are supported:
%%
%a
%A
day of week, using locale's weekday names; either the abbreviated or full name
may be specified
%b
%B
%h
month, using locale's month names; either the abbreviated or full name
may be specified
%c
%C
date and time, in locale's long-format date and time representation
%d
%e
day of month (1-31; leading zeroes are permitted but not required)
%D
%H
%k
hour (0-23; leading zeroes are permitted but not required)
%I
%l
hour (0-12; leading zeroes are permitted but not required)
%j
day number of year (001-366)
%m
month number (1-12; leading zeroes are permitted but not required)
%M
minute (0-59; leading zeroes are permitted but not required)
%p
locale's equivalent of
or
%r
%R
%S
seconds (0-61; leading zeroes are permitted but not required. Extra second
allowed for leap years)
%T
%w
weekday number (0-6) with Sunday as the first day of the week
%x
date, using locale's date format
%X
time, using locale's time format
%y
year within century (0-99; leading zeroes are permitted but not required.
Unfortunately this makes the assumption that we are stuck in the 20th
century as 1900 is automatically added onto this number for the tm_year
field)
%Y
year, including century (for example, 1988)
Case is ignored when matching items such as month or weekday names.
The broken-down time structure tm is defined in <time.h>
as follows:
12
8n 16n 32n
struct tm
{
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
RETURN VALUE
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 NUL
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.
SEE ALSO
NOTES
The specification of the function in the XPG standard is rather vague.
It leaves out a few important pieces of information. Most important
it does not specify what happens to those elements of tm which
are not directly initialized by the different formats. Various
implementations on different Unix systems vary here.
The GNU libc implementation does not touch those fields which are not
directly initialized. Exceptions are the
tm_wday
and
tm_yday
elements which are recomputed if any of the year, month,
or date elements changed.
This function is only available in libraries newer than version 4.6.5.
Linux libc4 and libc5 includes define the prototype unconditionally;
glibc2 includes provide a prototype only when _XOPEN_SOURCE or _GNU_SOURCE
are defined.
The function supports only those locales specified in
locale (7)
man3/strchr.3
|