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