xref: /freebsd/lib/libc/stdtime/strptime.3 (revision c68159a6d8eede11766cf13896d0f7670dbd51aa)
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.An J\(:org Wunsch .
91.Sh HISTORY
92The
93.Fn strptime
94function appeared in
95.Fx 3.0 .
96.Pp
97.Sh BUGS
98Both the
99.Fa %e
100and
101.Fa %l
102format specifiers may incorrectly scan one too many digits
103if the intended values comprise only a single digit
104and that digit is followed immediately by another digit.
105Both specifiers accept zero-padded values,
106even though they are both defined as taking unpadded values.
107.Pp
108The
109.Fa %p
110format specifier has no effect unless it is parsed
111.Em after
112hour-related specifiers.
113Specifying
114.Fa %l
115without
116.Fa %p
117will produce undefined results.
118Note that 12AM
119.Pq ante meridiem
120is taken as midnight
121and 12PM
122.Pq post meridiem
123is taken as noon.
124.Pp
125The
126.Fa %U
127and
128.Fa %W
129format specifiers accept any value within the range 00 to 53
130without validating against other values supplied (like month
131or day of the year, for example).
132.Pp
133The
134.Fa %Z
135format specifier only accepts time zone abbreviations of the local time zone,
136or the value "GMT".
137This limitation is because of ambiguity due to of the over loading of time
138zone abbreviations.  One such example is
139.Fa EST
140which is both Eastern Standard Time and Eastern Australia Summer Time.
141