xref: /dragonfly/lib/libc/stdtime/strptime.3 (revision 6ab64ab6)
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: head/lib/libc/stdtime/strptime.3 272533 2014-10-04 18:00:15Z pfg $
27.\" "
28.Dd August 7, 2016
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.In time.h
38.Ft char *
39.Fo strptime
40.Fa "const char * restrict buf"
41.Fa "const char * restrict format"
42.Fa "struct tm * restrict timeptr"
43.Fc
44.In time.h
45.In xlocale.h
46.Ft char *
47.Fn strptime_l "const char * restrict buf" "const char * restrict format" "struct tm * restrict timeptr" "locale_t loc"
48.Sh DESCRIPTION
49The
50.Fn strptime
51function parses the string in the buffer
52.Fa buf
53according to the string pointed to by
54.Fa format ,
55and fills in the elements of the structure pointed to by
56.Fa timeptr .
57The resulting values will be relative to the local time zone.
58Thus, it can be considered the reverse operation of
59.Xr strftime 3 .
60The
61.Fn strptime_l
62function does the same as
63.Fn strptime ,
64but takes an explicit locale rather than using the current locale.
65.Pp
66The
67.Fa format
68string consists of zero or more conversion specifications and
69ordinary characters.
70All ordinary characters are matched exactly with the buffer, where
71white space in the format string will match any amount of white space
72in the buffer.
73All conversion specifications are identical to those described in
74.Xr strftime 3 .
75.Pp
76Two-digit year values, including formats
77.Fa %y
78and
79.Fa \&%D ,
80are now interpreted as beginning at 1969 per POSIX requirements.
81Years 69-00 are interpreted in the 20th century (1969-2000), years
8201-68 in the 21st century (2001-2068).
83Four-digit year values in
84.Fa \&%Y
85specifier are interpreted as days since year 1900
86as per POSIX requirements.
87The
88.Fa \&%U
89and
90.Fa %W
91format specifiers accept any value within the range 00 to 53.
92.Pp
93The time zone
94.Fa \&%z
95format specifier accepts both RFC 822 (+hhmm) and ISO 8601 (+hhmm +hh:mm +hh Z)
96standard time zone formats.
97The -00, -00:00, -0000 time zone values are also accepted as per RFC 3339.
98.Pp
99If the
100.Fa format
101string does not contain enough conversion specifications to completely
102specify the resulting
103.Vt struct tm ,
104the unspecified members of
105.Va timeptr
106are left untouched.
107For example, if
108.Fa format
109is
110.Dq Li "%H:%M:%S" ,
111only
112.Va tm_hour ,
113.Va tm_sec
114and
115.Va tm_min
116will be modified.
117If time relative to today is desired, initialize the
118.Fa timeptr
119structure with today's date before passing it to
120.Fn strptime .
121.Sh RETURN VALUES
122Upon successful completion,
123.Fn strptime
124returns the pointer to the first character in
125.Fa buf
126that has not been required to satisfy the specified conversions in
127.Fa format .
128It returns
129.Dv NULL
130if one of the conversions failed.
131.Fn strptime_l
132returns the same values as
133.Fn strptime .
134.Sh SEE ALSO
135.Xr date 1 ,
136.Xr scanf 3 ,
137.Xr strftime 3
138.Sh HISTORY
139The
140.Fn strptime
141function appeared in
142.Fx 3.0 .
143.Sh AUTHORS
144The
145.Fn strptime
146function has been contributed by Powerdog Industries.
147.Pp
148This man page was written by
149.An J\(:org Wunsch .
150.Sh BUGS
151Both the
152.Fa %e
153and
154.Fa %l
155format specifiers may incorrectly scan one too many digits
156if the intended values comprise only a single digit
157and that digit is followed immediately by another digit.
158Both specifiers accept zero-padded values,
159even though they are both defined as taking unpadded values.
160.Pp
161The
162.Fa %p
163format specifier has no effect unless it is parsed
164.Em after
165hour-related specifiers.
166Specifying
167.Fa %l
168without
169.Fa %p
170will produce undefined results.
171Note that 12AM
172(ante meridiem)
173is taken as midnight
174and 12PM
175(post meridiem)
176is taken as noon.
177.Pp
178The
179.Fa %Z
180format specifier only accepts time zone abbreviations of the local time zone,
181or the value "GMT".
182This limitation is because of ambiguity due to of the over loading of time
183zone abbreviations.
184One such example is
185.Fa EST
186which is both Eastern Standard Time and Eastern Australia Summer Time.
187.Pp
188The
189.Fn strptime
190function does not correctly handle multibyte characters in the
191.Fa format
192argument.
193