xref: /freebsd/lib/libc/stdtime/strptime.3 (revision 23f282aa31e9b6fceacd449020e936e98d6f2298)
1.\"
2.\" Copyright (c) 1997 Joerg Wunsch
3.\"
4.\" All rights reserved.
5.\"
6.\" Redistribution and use in source and binary forms, with or without
7.\" modification, are permitted provided that the following conditions
8.\" are met:
9.\" 1. Redistributions of source code must retain the above copyright
10.\"    notice, this list of conditions and the following disclaimer.
11.\" 2. Redistributions in binary form must reproduce the above copyright
12.\"    notice, this list of conditions and the following disclaimer in the
13.\"    documentation and/or other materials provided with the distribution.
14.\"
15.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
16.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
19.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25.\"
26.\" $FreeBSD$
27.\" "
28.Dd May 8, 1997
29.Dt STRPTIME 3
30.Os
31.Sh NAME
32.Nm strptime
33.Nd parse date and time string
34.Sh LIBRARY
35.Lb libc
36.Sh SYNOPSIS
37.Fd #include <time.h>
38.Ft char *
39.Fn strptime "const char *buf" "const char *format" "struct tm *timeptr"
40.Sh DESCRIPTION
41The
42.Fn strptime
43function parses the string in the buffer
44.Fa buf
45according to the string pointed to by
46.Fa format ,
47and fills in the elements of the structure pointed to by
48.Fa timeptr .
49The resulting values will be relative to the local time zone.
50Thus, it can be considered the reverse operation of
51.Xr strftime 3 .
52.Pp
53The
54.Fa format
55string consists of zero or more conversion specifications and
56ordinary characters.
57All ordinary characters are matched exactly with the buffer, where
58white space in the format string will match any amount of white space
59in the buffer.
60All conversion specifications are identical to those described in
61.Xr strftime 3 .
62.Pp
63Two-digit year values, including formats
64.Fa %y
65and
66.Fa %D ,
67are now interpreted as beginning at 1969 per POSIX requirements.
68Years 69-00 are interpreted in the 20th century (1969-2000), years
6901-68 in the 21st century (2001-2068).
70.Sh RETURN VALUES
71Upon successful completion,
72.Fn strptime
73returns the pointer to the first character in
74.Fa buf
75that has not been required to satisfy the specified conversions in
76.Fa format .
77It returns
78.Dv NULL
79if one of the conversions failed.
80.Sh SEE ALSO
81.Xr date 1 ,
82.Xr scanf 3 ,
83.Xr strftime 3
84.Sh AUTHORS
85The
86.Fn strptime
87function has been contributed by Powerdog Industries.
88.Pp
89This man page was written by
90.ie t J\(:org Wunsch.
91.el Joerg Wunsch.
92.Sh HISTORY
93The
94.Fn strptime
95function appeared in
96.Fx 3.0 .
97.Pp
98.Sh BUGS
99Both the
100.Fa %e
101and
102.Fa %l
103format specifiers may incorrectly scan one too many digits
104if the intended values comprise only a single digit
105and that digit is followed immediately by another digit.
106Both specifiers accept zero-padded values,
107even though they are both defined as taking unpadded values.
108.Pp
109The
110.Fa %p
111format specifier has no effect unless it is parsed
112.Em after
113hour-related specifiers.
114Specifying
115.Fa %l
116without
117.Fa %p
118will produce undefined results.
119Note that 12AM
120.Pq ante meridiem
121is taken as midnight
122and 12PM
123.Pq post meridiem
124is taken as noon.
125.Pp
126The
127.Fa %U
128and
129.Fa %W
130format specifiers accept any value within the range 00 to 53
131without validating against other values supplied (like month
132or day of the year, for example).
133.Pp
134The
135.Fa %Z
136format specifier only accepts time zone abbreviations of the local time zone,
137or the value "GMT".
138This limitation is because of ambiguity due to of the over loading of time
139zone abbreviations.  One such example is
140.Fa EST
141which is both Eastern Standard Time and Eastern Australia Summer Time.
142