| STRPTIME(3) | Library Functions Manual | STRPTIME(3) |
strptime —
converts a character string to a time value
Standard C Library (libc, -lc)
#include
<time.h>
char *
strptime(const char * restrict
buf, const char * restrict format,
struct tm * restrict timeptr);
char *
strptime_l(const char * restrict
buf, const char * restrict format,
struct tm * restrict timeptr, locale_t
loc);
The
strptime()
function converts the character string pointed to by
buf according to the string pointed to by
format, and fills in the elements of the structure
pointed to by timeptr. The resulting values will be
relative to the local time zone. Thus, it can be considered the reverse
operation of strftime(3).
The
strptime_l()
function does the same as strptime(), but takes an
explicit locale in the locale_t
loc argument rather than using the current locale.
The format string consists
of zero or more conversion specifications and ordinary characters. All
ordinary characters in are compared directly against the corresponding
characters in buf; comparisons which fail will cause
strptime()
to fail. Whitespace characters in format match any
number of whitespace characters in buf, including
none. All conversion specifications are identical to those described in
strftime(3).
Two-digit year values, including formats %y and %D, are now interpreted as beginning at 1969 per POSIX requirements. Years 69-00 are interpreted in the 20th century (1969-2000), years 01-68 in the 21st century (2001-2068). The %U and %W format specifiers accept any value within the range 00 to 53.
If the format string does
not contain enough conversion specifications to completely specify the
resulting struct tm, the unspecified members of
timeptr are left untouched. For example, if
format is
“%H:%M:%S”, only
tm_hour, tm_sec
tm_min will be modified. If time relative to today is
desired, initialize the timeptr structure with today's
date before passing it to
strptime().
All ordinary characters in are compared directly against the corresponding
characters in buf; comparisons which fail will cause
strptime() to fail. Whitespace characters in
format match any number of whitespace characters in
buf, including none.
A conversion specification consists of a percent sign
‘%’ followed by one or two conversion
characters which specify the replacement required. There must be white-space
or other non-alphanumeric characters between any two conversion
specifications.
Conversion of alphanumeric strings (such as month
and weekday names) is done without regard to case. Conversion specifications
which cannot be matched will cause
strptime()
to fail.
The LC_TIME category defines the locale values for the conversion specifications. The following conversion specifications are supported:
%a%A%a.%b%B%b.%c%C%d%D%e%d.%F%g%G%h%b.%H%I%j%k%H.%l%I.%m%M%n%p%r%R%S%s%t%T%u%U%V%w%W%x%X%y%Y%zUTC’) specified as:
UTC’ specified as:
Coordinated Universal
Time’)Greenwich Mean
Time’)Universal Time’)Zulu Time’)Eastern’ (“E”),
‘Central’ (“C”),
‘Mountain’ (“M”)
or ‘Pacific’
(“P”), and the second letter standing for
‘Daylight’ (“D” or
summer) time or ‘Standard’
(“S”) time%Z%%For compatibility, certain conversion specifications can be
modified by the E and O
modifier characters to indicate that an alternative format or specification
should be used rather than the one normally used by the unmodified
conversion specification. As there are currently neither alternative formats
nor specifications supported by the system, the behavior will be as if the
unmodified conversion specification were used.
Case is ignored when matching string items in buf, such as month and weekday names.
If successful, the strptime() function
returns a pointer to the character following the last character parsed.
Otherwise, a NULL pointer is returned.
The strptime() function conforms to
X/Open Portability Guide Issue 4
(“XPG4”).
The %Z format specifier only accepts time
zone abbreviations of the local time zone, or the values “GMT”
or “UTC”. This limitation is caused by the ambiguity of
overloaded time zone abbreviations, for example EST is both Eastern Standard
Time and Eastern Australia Summer Time.
| April 6, 2025 | NetBSD 11.0 |