xref: /dragonfly/lib/libc/stdtime/strptime.3 (revision 49781055)
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: src/lib/libc/stdtime/strptime.3,v 1.9.2.9 2003/05/24 00:01:31 keramida Exp $
27.\" $DragonFly: src/lib/libc/stdtime/strptime.3,v 1.3 2006/02/17 19:35:06 swildner Exp $
28.\" "
29.Dd January 4, 2003
30.Dt STRPTIME 3
31.Os
32.Sh NAME
33.Nm strptime
34.Nd parse date and time string
35.Sh LIBRARY
36.Lb libc
37.Sh SYNOPSIS
38.In time.h
39.Ft char *
40.Fo strptime
41.Fa "const char * restrict buf"
42.Fa "const char * restrict format"
43.Fa "struct tm * restrict timeptr"
44.Fc
45.Sh DESCRIPTION
46The
47.Fn strptime
48function parses the string in the buffer
49.Fa buf
50according to the string pointed to by
51.Fa format ,
52and fills in the elements of the structure pointed to by
53.Fa timeptr .
54The resulting values will be relative to the local time zone.
55Thus, it can be considered the reverse operation of
56.Xr strftime 3 .
57.Pp
58The
59.Fa format
60string consists of zero or more conversion specifications and
61ordinary characters.
62All ordinary characters are matched exactly with the buffer, where
63white space in the format string will match any amount of white space
64in the buffer.
65All conversion specifications are identical to those described in
66.Xr strftime 3 .
67.Pp
68Two-digit year values, including formats
69.Fa %y
70and
71.Fa \&%D ,
72are now interpreted as beginning at 1969 per POSIX requirements.
73Years 69-00 are interpreted in the 20th century (1969-2000), years
7401-68 in the 21st century (2001-2068).
75.Pp
76If the
77.Fa format
78string does not contain enough conversion specifications to completely
79specify the resulting
80.Vt struct tm ,
81the unspecified members of
82.Va timeptr
83are left untouched.
84For example, if
85.Fa format
86is
87.Dq Li "%H:%M:%S" ,
88only
89.Va tm_hour ,
90.Va tm_sec
91and
92.Va tm_min
93will be modified.
94If time relative to today is desired, initialize the
95.Fa timeptr
96structure with today's date before passing it to
97.Fn strptime .
98.Sh RETURN VALUES
99Upon successful completion,
100.Fn strptime
101returns the pointer to the first character in
102.Fa buf
103that has not been required to satisfy the specified conversions in
104.Fa format .
105It returns
106.Dv NULL
107if one of the conversions failed.
108.Sh SEE ALSO
109.Xr date 1 ,
110.Xr scanf 3 ,
111.Xr strftime 3
112.Sh HISTORY
113The
114.Fn strptime
115function appeared in
116.Fx 3.0 .
117.Sh AUTHORS
118The
119.Fn strptime
120function has been contributed by Powerdog Industries.
121.Pp
122This man page was written by
123.An J\(:org Wunsch .
124.Sh BUGS
125Both the
126.Fa %e
127and
128.Fa %l
129format specifiers may incorrectly scan one too many digits
130if the intended values comprise only a single digit
131and that digit is followed immediately by another digit.
132Both specifiers accept zero-padded values,
133even though they are both defined as taking unpadded values.
134.Pp
135The
136.Fa %p
137format specifier has no effect unless it is parsed
138.Em after
139hour-related specifiers.
140Specifying
141.Fa %l
142without
143.Fa %p
144will produce undefined results.
145Note that 12AM
146(ante meridiem)
147is taken as midnight
148and 12PM
149(post meridiem)
150is taken as noon.
151.Pp
152The
153.Fa %U
154and
155.Fa %W
156format specifiers accept any value within the range 00 to 53
157without validating against other values supplied (like month
158or day of the year, for example).
159.Pp
160The
161.Fa %Z
162format specifier only accepts time zone abbreviations of the local time zone,
163or the value "GMT".
164This limitation is because of ambiguity due to of the over loading of time
165zone abbreviations.  One such example is
166.Fa EST
167which is both Eastern Standard Time and Eastern Australia Summer Time.
168.Pp
169The
170.Fn strptime
171function does not correctly handle multibyte characters in the
172.Fa format
173argument.
174