STRPTIME(3C) | Standard C Library Functions | STRPTIME(3C) |
strptime, strptime_l - date and time conversion
#include <time.h> char *strptime(const char *restrict buf,
const char *restrict format, struct tm *restrict tm);
#include <time.h> #include <xlocale.h> char *strptime_l(const char *restrict buf,
const char *restrict format, struct tm *restrict tm,
locale_t loc);
cc [flag...] file... -D_STRPTIME_DONTZERO [library...] #include <time.h> char *strptime(const char *restrict buf,
const char *restrict format, struct tm *restrict tm);
The strptime() function converts the character string pointed to by buf to values which are stored in the tm structure pointed to by tm, using the format specified by format. The strptime_l() function is identical to strptime() except instead of acting in the current locale, it acts in the locale specified by the argument loc.
The format argument is composed of zero or more conversion specifications. Each conversion specification is composed of a "%" (percent) character followed by one or two conversion characters which specify the replacement required. One or more white space characters (as specified by isspace(3C)) may precede or follow a conversion specification. There must be white-space or other non-alphanumeric characters between any two conversion specifications.
A non-zeroing version of strptime(), described below under Non-zeroing Behavior, is provided if _STRPTIME_DONTZERO is defined.
The following conversion specifications are supported:
%%
%a
%A
%b
%B
%c
%C
%d
%D
%e
%h
%H
%I
%j
%m
%M
%n
%p
%r
%R
%S
%S
%t
%T
%U
%w
%W
%x
%X
%y
%Y
%Z
Some conversion specifications can be modified by the E and O modifier characters to indicate that an alternate format or specification should be used rather than the one normally used by the unmodified specification. If the alternate format or specification does not exist in the current locale, the behavior will be as if the unmodified conversion specification were used.
%Ec
%EC
%Ex
%EX
%Ey
%EY
%Od
%Oe
%OH
%OI
%Om
%OM
%OS
%OU
%Ow
%OW
%Oy
A conversion specification that is an ordinary character is executed by scanning the next character from the buffer. If the character scanned from the buffer differs from the one comprising the specification, the specification fails, and the differing and subsequent characters remain unscanned.
A series of specifications composed of %n, %t, white-space characters or any combination is executed by scanning up to the first character that is not white space (which remains unscanned), or until no more characters can be scanned. White space is defined by isspace(3C).
Any other conversion specification is executed by scanning characters until a character matching the next specification is scanned, or until no more characters can be scanned. These characters, except the one matching the next specification, are then compared to the locale values associated with the conversion specifier. If a match is found, values for the appropriate tm structure members are set to values corresponding to the locale information. If no match is found, strptime() fails and no more characters are scanned.
The month names, weekday names, era names, and alternate numeric symbols can consist of any combination of upper and lower case letters. The user can request that the input date or time specification be in a specific language by setting the LC_TIME category using setlocale(3C).
In addition to the behavior described above by various standards, the Solaris implementation of strptime() provides the following extensions. These may change at any time in the future. Portable applications should not depend on these extended features:
The following describes extended features regardless of whether _STRPTIME_DONTZERO is defined or not defined:
The following describes extended features when _STRPTIME_DONTZERO is not defined:
The following describes extended features when _STRPTIME_DONTZERO is defined:
Upon successful completion, strptime() returns a pointer to the character following the last character parsed. Otherwise, a null pointer is returned.
Several "same as" formats, and the special processing of white-space characters are provided in order to ease the use of identical format strings for strftime(3C) and strptime().
The strptime() function tries to calculate tm_year, tm_mon, and tm_mday when given incomplete input. This allows the struct tm created by strptime() to be passed to mktime(3C) to produce a time_t value for dates and times that are representable by a time_t. As an example, since mktime() ignores tm_yday, strptime() calculates tm_mon and tm_mday as well as filling in tm_yday when %j is specified without otherwise specifying a month and day within month.
See attributes(7) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
CSI | Enabled |
Interface Stability | See below. |
MT-Level | MT-Safe |
Standard | See standards(7) for strptime(). |
The strptime() function is Standard. The strptime_l() function is Uncommitted.
ctime(3C), getdate(3C), isspace(3C), mktime(3C), newlocale(3C), setlocale(3C), strftime(3C), uselocale(3C), attributes(7), environ(7), standards(7)
June 27, 2014 | OmniOS |