]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strptime.3
Automated unformatting of parentheses using unformat_parens.sh
[thirdparty/man-pages.git] / man3 / strptime.3
1 .\" Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date. The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein. The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Modified, jmv@lucifer.dorms.spbu.ru, 1999-11-08
24 .\" Modified, aeb, 2000-04-07
25 .\" Updated from glibc docs, C. Scott Ananian, 2001-08-25
26 .\" Modified, aeb, 2001-08-31
27 .\" Modified, wharms 2001-11-12, remark on white space and example
28 .\"
29 .TH STRPTIME 3 2001-11-12 "GNU" "Linux Programmer's Manual"
30 .SH NAME
31 strptime \- convert a string representation of time to a time tm structure
32 .SH SYNOPSIS
33 .BR "#define _XOPEN_SOURCE" " /* glibc2 needs this */"
34 .br
35 .B #include <time.h>
36 .sp
37 .BI "char *strptime(const char *" s ", const char *" format ,
38 .BI "struct tm *" tm );
39 .SH DESCRIPTION
40 The
41 .BR strptime ()
42 function is the converse function to
43 .BR strftime ()
44 and converts the character string pointed to by
45 .I s
46 to values which are stored in the
47 .B tm
48 structure pointed to by
49 .IR tm ,
50 using the format specified by
51 .IR format .
52 Here
53 .I format
54 is a character string that consists of field descriptors and text characters,
55 reminiscent of
56 .BR scanf (3).
57 Each field descriptor consists of a
58 .B %
59 character followed by another character that specifies the replacement
60 for the field descriptor.
61 All other characters in the
62 .I format
63 string must have a matching character in the input string,
64 except for whitespace, which matches zero or more
65 whitespace characters in the input string.
66 There should be white\%space or other alphanumeric characters
67 between any two field descriptors.
68 .PP
69 The \fBstrptime\fP() function processes the input string from left
70 to right. Each of the three possible input elements (whitespace,
71 literal, or format) are handled one after the other. If the input
72 cannot be matched to the format string the function stops. The
73 remainder of the format and input strings are not processed.
74 .PP
75 The supported input field descriptors are listed below.
76 In case a text string (such as a weekday or month name)
77 is to be matched, the comparison is case insensitive.
78 In case a number is to be matched, leading zeros are
79 permitted but not required.
80 .TP
81 .B %%
82 The
83 .B %
84 character.
85 .TP
86 .BR %a " or " %A
87 The weekday name according to the current locale,
88 in abbreviated form or the full name.
89 .TP
90 .BR %b " or " %B " or " %h
91 The month name according to the current locale,
92 in abbreviated form or the full name.
93 .TP
94 .B %c
95 The date and time representation for the current locale.
96 .TP
97 .B %C
98 The century number (0-99).
99 .TP
100 .BR %d " or " %e
101 The day of month (1-31).
102 .TP
103 .B %D
104 Equivalent to %m/%d/%y. (This is the American style date, very confusing
105 to non-Americans, especially since %d/%m/%y is widely used in Europe.
106 The ISO 8601 standard format is %Y-%m-%d.)
107 .TP
108 .BR %H
109 The hour (0-23).
110 .TP
111 .BR %I
112 The hour on a 12-hour clock (1-12).
113 .TP
114 .B %j
115 The day number in the year (1-366).
116 .TP
117 .B %m
118 The month number (1-12).
119 .TP
120 .B %M
121 The minute (0-59).
122 .TP
123 .B %n
124 Arbitrary whitespace.
125 .TP
126 .B %p
127 The locale's equivalent of AM or PM. (Note: there may be none.)
128 .TP
129 .B %r
130 The 12-hour clock time (using the locale's AM or PM).
131 In the POSIX locale equivalent to %I:%M:%S %p.
132 If \fIt_fmt_ampm\fP is empty in the LC_TIME part of the current locale
133 then the behaviour is undefined.
134 .TP
135 .B %R
136 Equivalent to %H:%M.
137 .TP
138 .B %S
139 The second (0-60; 60 may occur for leap seconds; earlier also 61 was allowed).
140 .TP
141 .B %t
142 Arbitrary whitespace.
143 .TP
144 .B %T
145 Equivalent to %H:%M:%S.
146 .TP
147 .B %U
148 The week number with Sunday the first day of the week (0-53).
149 The first Sunday of January is the first day of week 1.
150 .TP
151 .B %w
152 The weekday number (0-6) with Sunday = 0.
153 .TP
154 .B %W
155 The week number with Monday the first day of the week (0-53).
156 The first Monday of January is the first day of week 1.
157 .TP
158 .B %x
159 The date, using the locale's date format.
160 .TP
161 .B %X
162 The time, using the locale's time format.
163 .TP
164 .B %y
165 The year within century (0-99).
166 When a century is not otherwise specified, values in the range 69-99 refer
167 to years in the twentieth century (1969-1999); values in the
168 range 00-68 refer to years in the twenty-first century (2000-2068).
169 .TP
170 .B %Y
171 The year, including century (for example, 1991).
172 .LP
173 Some field descriptors can be modified by the E or O modifier characters
174 to indicate that an alternative format or specification should be used. If the
175 alternative format or specification does not exist in the current locale, the
176 unmodified field descriptor is used.
177 .LP
178 The E modifier specifies that the input string may contain
179 alternative locale-dependent versions of the date and time representation:
180 .TP
181 .B %Ec
182 The locale's alternative date and time representation.
183 .TP
184 .B %EC
185 The name of the base year (period) in the locale's alternative representation.
186 .TP
187 .B %Ex
188 The locale's alternative date representation.
189 .TP
190 .B %EX
191 The locale's alternative time representation.
192 .TP
193 .B %Ey
194 The offset from %EC (year only) in the locale's alternative representation.
195 .TP
196 .B %EY
197 The full alternative year representation.
198 .LP
199 The O modifier specifies that the numerical input may be in an
200 alternative locale-dependent format:
201 .TP
202 .BR %Od " or " %Oe
203 The day of the month using the locale's alternative numeric symbols;
204 leading zeros are permitted but not required.
205 .TP
206 .B %OH
207 The hour (24-hour clock) using the locale's alternative numeric symbols.
208 .TP
209 .B %OI
210 The hour (12-hour clock) using the locale's alternative numeric symbols.
211 .TP
212 .B %Om
213 The month using the locale's alternative numeric symbols.
214 .TP
215 .B %OM
216 The minutes using the locale's alternative numeric symbols.
217 .TP
218 .B %OS
219 The seconds using the locale's alternative numeric symbols.
220 .TP
221 .B %OU
222 The week number of the year (Sunday as the first day of the week)
223 using the locale's alternative numeric symbols.
224 .TP
225 .B %Ow
226 The number of the weekday (Sunday=0) using the locale's alternative
227 numeric symbols.
228 .TP
229 .B %OW
230 The week number of the year (Monday as the first day of the week)
231 using the locale's alternative numeric symbols.
232 .TP
233 .B %Oy
234 The year (offset from %C) using the locale's alternative numeric symbols.
235 .LP
236 The broken-down time structure \fItm\fP is defined in \fI<time.h>\fP
237 as follows:
238 .sp
239 .RS
240 .nf
241 .ne 12
242 .ta 8n 16n 32n
243 struct tm {
244 int tm_sec; /* seconds */
245 int tm_min; /* minutes */
246 int tm_hour; /* hours */
247 int tm_mday; /* day of the month */
248 int tm_mon; /* month */
249 int tm_year; /* year */
250 int tm_wday; /* day of the week */
251 int tm_yday; /* day in the year */
252 int tm_isdst; /* daylight saving time */
253 };
254 .ta
255 .fi
256 .RE
257 .SH "RETURN VALUE"
258 The return value of the function is a pointer to the first character
259 not processed in this function call. In case the input string
260 contains more characters than required by the format string the return
261 value points right after the last consumed input character. In case
262 the whole input string is consumed the return value points to the NUL
263 byte at the end of the string. If \fBstrptime\fP() fails to match all
264 of the format string and therefore an error occurred the function
265 returns \fBNULL\fP.
266 .SH "CONFORMING TO"
267 XPG4, SUSv2, POSIX 1003.1-2001.
268 .SH EXAMPLE
269 The following example demonstrates the use of \fBstrptime\fP()
270 and \fBstrftime\fP().
271 .sp
272 .nf
273 .ne 12
274 .ta 8n 16n
275 #include <stdio.h>
276 #include <time.h>
277
278 int main() {
279 struct tm tm;
280 char buf[255];
281
282 strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
283 strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
284 puts(buf);
285 return 0;
286 }
287 .ta
288 .fi
289 .SH "GNU EXTENSIONS"
290 For reasons of symmetry, glibc tries to support for
291 .BR strptime ()
292 the same format characters as for
293 .BR strftime .
294 (In most cases the corresponding fields are parsed, but no field in \fItm\fP
295 is changed.)
296 This leads to
297 .TP
298 .B %F
299 Equivalent to \fB%Y-%m-%d\fP, the ISO 8601 date format.
300 .TP
301 .B %g
302 The year corresponding to the ISO week number, but without the century
303 (0-99).
304 .TP
305 .B %G
306 The year corresponding to the ISO week number. (For example, 1991.)
307 .TP
308 .B %u
309 The day of the week as a decimal number (1-7, where Monday = 1).
310 .TP
311 .B %V
312 The ISO 8601:1988 week number as a decimal number (1-53).
313 If the week (starting on Monday) containing 1 January has four or more days
314 in the new year, then it is considered week 1. Otherwise, it is the last week
315 of the previous year, and the next week is week 1.
316 .TP
317 .B %z
318 An RFC-822/ISO 8601 standard time zone specification.
319 .TP
320 .B %Z
321 The timezone name.
322 .LP
323 Similarly, because of GNU extensions to \fIstrftime\fP,
324 %k is accepted as a synonym for %H, and %l should be accepted
325 as a synonym for %I, and %P is accepted as a synonym for %p.
326 Finally
327 .TP
328 .B %s
329 The number of seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC.
330 Leap seconds are not counted unless leap second support is available.
331 .LP
332 The GNU libc implementation does not require whitespace between
333 two field descriptors.
334 .SH NOTES
335 .LP
336 In principle, this function does not initialize \fBtm\fP but
337 only stores the values specified.
338 This means that \fBtm\fP should be initialized before the call.
339 Details differ a bit between different Unix systems.
340 The GNU libc implementation does not touch those fields which are not
341 explicitly specified, except that it recomputes the
342 .IR tm_wday
343 and
344 .IR tm_yday
345 field if any of the year, month, or day elements changed.
346 .PP
347 This function is available since libc 4.6.8.
348 Linux libc4 and libc5 includes define the prototype unconditionally;
349 glibc2 includes provide a prototype only when _XOPEN_SOURCE or _GNU_SOURCE
350 are defined.
351 .PP
352 Before libc 5.4.13 whitespace (and the 'n' and 't' specifications)
353 was not handled, no 'E' and 'O' locale modifier characters were accepted,
354 and the 'C' specification was a synonym for the 'c' specification.
355 .PP
356 The 'y' (year in century) specification is taken to specify a year
357 in the 20th century by libc4 and libc5. It is taken to be a year
358 in the range 1950-2049 by glibc 2.0. It is taken to be a year in
359 1969-2068 since glibc 2.1.
360 .\" In libc4 and libc5 the code for %I is broken (fixed in glibc;
361 .\" %OI was fixed in glibc 2.2.4).
362 .SH "SEE ALSO"
363 .BR time (2),
364 .BR getdate (3),
365 .BR scanf (3),
366 .BR setlocale (3),
367 .BR strftime (3)