609 lines
14 KiB
HTML
609 lines
14 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of STRPTIME</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>STRPTIME</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
strptime - convert a string representation of time to a time tm structure
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B>#define _XOPEN_SOURCE</B> /* See <A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A>(7) */
|
|
|
|
<BR>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/time.h">time.h</A>></B>
|
|
|
|
<P>
|
|
|
|
<B>char *strptime(const char *</B><I>s</I><B>, const char *</B><I>format</I><B>,</B>
|
|
|
|
<B>struct tm *</B><I>tm</I><B>);</B>
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>strptime</B>()
|
|
|
|
function is the converse of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3);
|
|
|
|
it converts the character string pointed to by
|
|
<I>s</I>
|
|
|
|
to values which are stored in the
|
|
"broken-down time"
|
|
structure pointed to by
|
|
<I>tm</I>,
|
|
|
|
using the format specified by
|
|
<I>format</I>.
|
|
|
|
<P>
|
|
|
|
The broken-down time structure
|
|
<I>tm</I>
|
|
|
|
is defined in
|
|
<I><<A HREF="file:///usr/include/time.h">time.h</A>></I>
|
|
|
|
as follows:
|
|
<P>
|
|
|
|
|
|
|
|
struct tm {
|
|
<BR> int tm_sec; /* Seconds (0-60) */
|
|
<BR> int tm_min; /* Minutes (0-59) */
|
|
<BR> int tm_hour; /* Hours (0-23) */
|
|
<BR> int tm_mday; /* Day of the month (1-31) */
|
|
<BR> int tm_mon; /* Month (0-11) */
|
|
<BR> int tm_year; /* Year - 1900 */
|
|
<BR> int tm_wday; /* Day of the week (0-6, Sunday = 0) */
|
|
<BR> int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */
|
|
<BR> int tm_isdst; /* Daylight saving time */
|
|
};
|
|
|
|
|
|
<P>
|
|
|
|
For more details on the
|
|
<I>tm</I>
|
|
|
|
structure, see
|
|
<B><A HREF="/cgi-bin/man/man2html?3+ctime">ctime</A></B>(3).
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>format</I>
|
|
|
|
argument
|
|
is a character string that consists of field descriptors and text characters,
|
|
reminiscent of
|
|
<B><A HREF="/cgi-bin/man/man2html?3+scanf">scanf</A></B>(3).
|
|
|
|
Each field descriptor consists of a
|
|
<B>%</B>
|
|
|
|
character followed by another character that specifies the replacement
|
|
for the field descriptor.
|
|
All other characters in the
|
|
<I>format</I>
|
|
|
|
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.
|
|
<P>
|
|
|
|
The
|
|
<B>strptime</B>()
|
|
|
|
function processes the input string from left
|
|
to right.
|
|
Each of the three possible input elements (whitespace,
|
|
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.
|
|
<P>
|
|
|
|
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.
|
|
<DL COMPACT>
|
|
<DT id="1"><B>%%</B>
|
|
|
|
<DD>
|
|
The
|
|
<B>%</B>
|
|
|
|
character.
|
|
<DT id="2"><B>%a</B> or <B>%A</B>
|
|
|
|
<DD>
|
|
The name of the day of the week according to the current locale,
|
|
in abbreviated form or the full name.
|
|
<DT id="3"><B>%b</B> or <B>%B</B> or <B>%h</B>
|
|
|
|
<DD>
|
|
The month name according to the current locale,
|
|
in abbreviated form or the full name.
|
|
<DT id="4"><B>%c</B>
|
|
|
|
<DD>
|
|
The date and time representation for the current locale.
|
|
<DT id="5"><B>%C</B>
|
|
|
|
<DD>
|
|
The century number (0-99).
|
|
<DT id="6"><B>%d</B> or <B>%e</B>
|
|
|
|
<DD>
|
|
The day of month (1-31).
|
|
<DT id="7"><B>%D</B>
|
|
|
|
<DD>
|
|
Equivalent to
|
|
<B>%m/%d/%y</B>.
|
|
|
|
(This is the American style date, very confusing
|
|
to non-Americans, especially since
|
|
<B>%d/%m/%y</B>
|
|
|
|
is widely used in Europe.
|
|
The ISO 8601 standard format is
|
|
<B>%Y-%m-%d</B>.)
|
|
|
|
<DT id="8"><B>%H</B>
|
|
|
|
<DD>
|
|
The hour (0-23).
|
|
<DT id="9"><B>%I</B>
|
|
|
|
<DD>
|
|
The hour on a 12-hour clock (1-12).
|
|
<DT id="10"><B>%j</B>
|
|
|
|
<DD>
|
|
The day number in the year (1-366).
|
|
<DT id="11"><B>%m</B>
|
|
|
|
<DD>
|
|
The month number (1-12).
|
|
<DT id="12"><B>%M</B>
|
|
|
|
<DD>
|
|
The minute (0-59).
|
|
<DT id="13"><B>%n</B>
|
|
|
|
<DD>
|
|
Arbitrary whitespace.
|
|
<DT id="14"><B>%p</B>
|
|
|
|
<DD>
|
|
The locale's equivalent of AM or PM.
|
|
(Note: there may be none.)
|
|
<DT id="15"><B>%r</B>
|
|
|
|
<DD>
|
|
The 12-hour clock time (using the locale's AM or PM).
|
|
In the POSIX locale equivalent to
|
|
<B>%I:%M:%S %p</B>.
|
|
|
|
If
|
|
<I>t_fmt_ampm</I>
|
|
|
|
is empty in the
|
|
<B>LC_TIME</B>
|
|
|
|
part of the current locale,
|
|
then the behavior is undefined.
|
|
<DT id="16"><B>%R</B>
|
|
|
|
<DD>
|
|
Equivalent to
|
|
<B>%H:%M</B>.
|
|
|
|
<DT id="17"><B>%S</B>
|
|
|
|
<DD>
|
|
The second (0-60; 60 may occur for leap seconds;
|
|
earlier also 61 was allowed).
|
|
<DT id="18"><B>%t</B>
|
|
|
|
<DD>
|
|
Arbitrary whitespace.
|
|
<DT id="19"><B>%T</B>
|
|
|
|
<DD>
|
|
Equivalent to
|
|
<B>%H:%M:%S</B>.
|
|
|
|
<DT id="20"><B>%U</B>
|
|
|
|
<DD>
|
|
The week number with Sunday the first day of the week (0-53).
|
|
The first Sunday of January is the first day of week 1.
|
|
<DT id="21"><B>%w</B>
|
|
|
|
<DD>
|
|
The ordinal number of the day of the week (0-6), with Sunday = 0.
|
|
<DT id="22"><B>%W</B>
|
|
|
|
<DD>
|
|
The week number with Monday the first day of the week (0-53).
|
|
The first Monday of January is the first day of week 1.
|
|
<DT id="23"><B>%x</B>
|
|
|
|
<DD>
|
|
The date, using the locale's date format.
|
|
<DT id="24"><B>%X</B>
|
|
|
|
<DD>
|
|
The time, using the locale's time format.
|
|
<DT id="25"><B>%y</B>
|
|
|
|
<DD>
|
|
The year within century (0-99).
|
|
When a century is not otherwise specified, values in the range 69-99 refer
|
|
to years in the twentieth century (1969-1999); values in the
|
|
range 00-68 refer to years in the twenty-first century (2000-2068).
|
|
<DT id="26"><B>%Y</B>
|
|
|
|
<DD>
|
|
The year, including century (for example, 1991).
|
|
</DL>
|
|
<P>
|
|
|
|
Some field descriptors can be modified by the E or O modifier characters
|
|
to indicate that an alternative format or specification should be used.
|
|
If the
|
|
alternative format or specification does not exist in the current locale, the
|
|
unmodified field descriptor is used.
|
|
<P>
|
|
|
|
The E modifier specifies that the input string may contain
|
|
alternative locale-dependent versions of the date and time representation:
|
|
<DL COMPACT>
|
|
<DT id="27"><B>%Ec</B>
|
|
|
|
<DD>
|
|
The locale's alternative date and time representation.
|
|
<DT id="28"><B>%EC</B>
|
|
|
|
<DD>
|
|
The name of the base year (period) in the locale's alternative representation.
|
|
<DT id="29"><B>%Ex</B>
|
|
|
|
<DD>
|
|
The locale's alternative date representation.
|
|
<DT id="30"><B>%EX</B>
|
|
|
|
<DD>
|
|
The locale's alternative time representation.
|
|
<DT id="31"><B>%Ey</B>
|
|
|
|
<DD>
|
|
The offset from
|
|
<B>%EC</B>
|
|
|
|
(year only) in the locale's alternative representation.
|
|
<DT id="32"><B>%EY</B>
|
|
|
|
<DD>
|
|
The full alternative year representation.
|
|
</DL>
|
|
<P>
|
|
|
|
The O modifier specifies that the numerical input may be in an
|
|
alternative locale-dependent format:
|
|
<DL COMPACT>
|
|
<DT id="33"><B>%Od</B> or <B>%Oe</B>
|
|
|
|
<DD>
|
|
The day of the month using the locale's alternative numeric symbols;
|
|
leading zeros are permitted but not required.
|
|
<DT id="34"><B>%OH</B>
|
|
|
|
<DD>
|
|
The hour (24-hour clock) using the locale's alternative numeric symbols.
|
|
<DT id="35"><B>%OI</B>
|
|
|
|
<DD>
|
|
The hour (12-hour clock) using the locale's alternative numeric symbols.
|
|
<DT id="36"><B>%Om</B>
|
|
|
|
<DD>
|
|
The month using the locale's alternative numeric symbols.
|
|
<DT id="37"><B>%OM</B>
|
|
|
|
<DD>
|
|
The minutes using the locale's alternative numeric symbols.
|
|
<DT id="38"><B>%OS</B>
|
|
|
|
<DD>
|
|
The seconds using the locale's alternative numeric symbols.
|
|
<DT id="39"><B>%OU</B>
|
|
|
|
<DD>
|
|
The week number of the year (Sunday as the first day of the week)
|
|
using the locale's alternative numeric symbols.
|
|
<DT id="40"><B>%Ow</B>
|
|
|
|
<DD>
|
|
The ordinal number of the day of the week (Sunday=0),
|
|
<BR> using the locale's alternative numeric symbols.
|
|
<DT id="41"><B>%OW</B>
|
|
|
|
<DD>
|
|
The week number of the year (Monday as the first day of the week)
|
|
using the locale's alternative numeric symbols.
|
|
<DT id="42"><B>%Oy</B>
|
|
|
|
<DD>
|
|
The year (offset from
|
|
<B>%C</B>)
|
|
|
|
using the locale's alternative numeric symbols.
|
|
</DL>
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
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
|
|
<B>strptime</B>()
|
|
|
|
fails to match all
|
|
of the format string and therefore an error occurred, the function
|
|
returns NULL.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>strptime</B>()
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe env locale<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<A NAME="lbAG"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2001, POSIX.1-2008, SUSv2.
|
|
<A NAME="lbAH"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
<P>
|
|
|
|
In principle, this function does not initialize
|
|
<I>tm</I>
|
|
|
|
but
|
|
stores only the values specified.
|
|
This means that
|
|
<I>tm</I>
|
|
|
|
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
|
|
<I>tm_wday</I>
|
|
|
|
and
|
|
<I>tm_yday</I>
|
|
|
|
field if any of the year, month, or day elements changed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<P>
|
|
|
|
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.
|
|
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Glibc notes</H3>
|
|
|
|
For reasons of symmetry, glibc tries to support for
|
|
<B>strptime</B>()
|
|
|
|
the same format characters as for
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3).
|
|
|
|
(In most cases, the corresponding fields are parsed, but no field in
|
|
<I>tm</I>
|
|
|
|
is changed.)
|
|
This leads to
|
|
<DL COMPACT>
|
|
<DT id="43"><B>%F</B>
|
|
|
|
<DD>
|
|
Equivalent to
|
|
<B>%Y-%m-%d</B>,
|
|
|
|
the ISO 8601 date format.
|
|
<DT id="44"><B>%g</B>
|
|
|
|
<DD>
|
|
The year corresponding to the ISO week number, but without the century
|
|
(0-99).
|
|
<DT id="45"><B>%G</B>
|
|
|
|
<DD>
|
|
The year corresponding to the ISO week number.
|
|
(For example, 1991.)
|
|
<DT id="46"><B>%u</B>
|
|
|
|
<DD>
|
|
The day of the week as a decimal number (1-7, where Monday = 1).
|
|
<DT id="47"><B>%V</B>
|
|
|
|
<DD>
|
|
The ISO 8601:1988 week number as a decimal number (1-53).
|
|
If the week (starting on Monday) containing 1 January has four or more days
|
|
in the new year, then it is considered week 1.
|
|
Otherwise, it is the last week
|
|
of the previous year, and the next week is week 1.
|
|
<DT id="48"><B>%z</B>
|
|
|
|
<DD>
|
|
An RFC-822/ISO 8601 standard timezone specification.
|
|
<DT id="49"><B>%Z</B>
|
|
|
|
<DD>
|
|
The timezone name.
|
|
</DL>
|
|
<P>
|
|
|
|
Similarly, because of GNU extensions to
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3),
|
|
|
|
<B>%k</B>
|
|
|
|
is accepted as a synonym for
|
|
<B>%H</B>,
|
|
|
|
and
|
|
<B>%l</B>
|
|
|
|
should be accepted
|
|
as a synonym for
|
|
<B>%I</B>,
|
|
|
|
and
|
|
<B>%P</B>
|
|
|
|
is accepted as a synonym for
|
|
<B>%p</B>.
|
|
|
|
Finally
|
|
<DL COMPACT>
|
|
<DT id="50"><B>%s</B>
|
|
|
|
<DD>
|
|
The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
|
|
Leap seconds are not counted unless leap second support is available.
|
|
</DL>
|
|
<P>
|
|
|
|
The glibc implementation does not require whitespace between
|
|
two field descriptors.
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
The following example demonstrates the use of
|
|
<B>strptime</B>()
|
|
|
|
and
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3).
|
|
|
|
<P>
|
|
|
|
|
|
#define _XOPEN_SOURCE
|
|
#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>>
|
|
#include <<A HREF="file:///usr/include/stdlib.h">stdlib.h</A>>
|
|
#include <<A HREF="file:///usr/include/string.h">string.h</A>>
|
|
#include <<A HREF="file:///usr/include/time.h">time.h</A>>
|
|
<P>
|
|
int
|
|
main(void)
|
|
{
|
|
<BR> struct tm tm;
|
|
<BR> char buf[255];
|
|
<P>
|
|
<BR> memset(&tm, 0, sizeof(struct tm));
|
|
<BR> strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
|
|
<BR> strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
|
|
<BR> puts(buf);
|
|
<BR> exit(EXIT_SUCCESS);
|
|
}
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?2+time">time</A></B>(2),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+getdate">getdate</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+scanf">scanf</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setlocale">setlocale</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+strftime">strftime</A></B>(3)
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="51"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="52"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="53"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="54"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="55"><A HREF="#lbAF">ATTRIBUTES</A><DD>
|
|
<DT id="56"><A HREF="#lbAG">CONFORMING TO</A><DD>
|
|
<DT id="57"><A HREF="#lbAH">NOTES</A><DD>
|
|
<DL>
|
|
<DT id="58"><A HREF="#lbAI">Glibc notes</A><DD>
|
|
</DL>
|
|
<DT id="59"><A HREF="#lbAJ">EXAMPLE</A><DD>
|
|
<DT id="60"><A HREF="#lbAK">SEE ALSO</A><DD>
|
|
<DT id="61"><A HREF="#lbAL">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:58 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|