]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/strptime.3
Wrapped long lines, wrapped at sentence boundaries; stripped trailing
[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.
71 Each of the three possible input elements (whitespace,
72 literal, or format) are handled one after the other.
73 If the input cannot be matched to the format string the function stops.
74 The remainder of the format and input strings are not processed.
75 .PP
76 The supported input field descriptors are listed below.
77 In case a text string (such as a weekday or month name)
78 is to be matched, the comparison is case insensitive.
79 In case a number is to be matched, leading zeros are
80 permitted but not required.
81 .TP
82 .B %%
83 The
84 .B %
85 character.
86 .TP
87 .BR %a " or " %A
88 The weekday name according to the current locale,
89 in abbreviated form or the full name.
90 .TP
91 .BR %b " or " %B " or " %h
92 The month name according to the current locale,
93 in abbreviated form or the full name.
94 .TP
95 .B %c
96 The date and time representation for the current locale.
97 .TP
98 .B %C
99 The century number (0-99).
100 .TP
101 .BR %d " or " %e
102 The day of month (1-31).
103 .TP
104 .B %D
105 Equivalent to %m/%d/%y.
106 (This is the American style date, very confusing
107 to non-Americans, especially since %d/%m/%y is widely used in Europe.
108 The ISO 8601 standard format is %Y-%m-%d.)
109 .TP
110 .BR %H
111 The hour (0-23).
112 .TP
113 .BR %I
114 The hour on a 12-hour clock (1-12).
115 .TP
116 .B %j
117 The day number in the year (1-366).
118 .TP
119 .B %m
120 The month number (1-12).
121 .TP
122 .B %M
123 The minute (0-59).
124 .TP
125 .B %n
126 Arbitrary whitespace.
127 .TP
128 .B %p
129 The locale's equivalent of AM or PM. (Note: there may be none.)
130 .TP
131 .B %r
132 The 12-hour clock time (using the locale's AM or PM).
133 In the POSIX locale equivalent to %I:%M:%S %p.
134 If \fIt_fmt_ampm\fP is empty in the LC_TIME part of the current locale
135 then the behaviour is undefined.
136 .TP
137 .B %R
138 Equivalent to %H:%M.
139 .TP
140 .B %S
141 The second (0-60; 60 may occur for leap seconds;
142 earlier also 61 was allowed).
143 .TP
144 .B %t
145 Arbitrary whitespace.
146 .TP
147 .B %T
148 Equivalent to %H:%M:%S.
149 .TP
150 .B %U
151 The week number with Sunday the first day of the week (0-53).
152 The first Sunday of January is the first day of week 1.
153 .TP
154 .B %w
155 The weekday number (0-6) with Sunday = 0.
156 .TP
157 .B %W
158 The week number with Monday the first day of the week (0-53).
159 The first Monday of January is the first day of week 1.
160 .TP
161 .B %x
162 The date, using the locale's date format.
163 .TP
164 .B %X
165 The time, using the locale's time format.
166 .TP
167 .B %y
168 The year within century (0-99).
169 When a century is not otherwise specified, values in the range 69-99 refer
170 to years in the twentieth century (1969-1999); values in the
171 range 00-68 refer to years in the twenty-first century (2000-2068).
172 .TP
173 .B %Y
174 The year, including century (for example, 1991).
175 .LP
176 Some field descriptors can be modified by the E or O modifier characters
177 to indicate that an alternative format or specification should be used.
178 If the
179 alternative format or specification does not exist in the current locale, the
180 unmodified field descriptor is used.
181 .LP
182 The E modifier specifies that the input string may contain
183 alternative locale-dependent versions of the date and time representation:
184 .TP
185 .B %Ec
186 The locale's alternative date and time representation.
187 .TP
188 .B %EC
189 The name of the base year (period) in the locale's alternative representation.
190 .TP
191 .B %Ex
192 The locale's alternative date representation.
193 .TP
194 .B %EX
195 The locale's alternative time representation.
196 .TP
197 .B %Ey
198 The offset from %EC (year only) in the locale's alternative representation.
199 .TP
200 .B %EY
201 The full alternative year representation.
202 .LP
203 The O modifier specifies that the numerical input may be in an
204 alternative locale-dependent format:
205 .TP
206 .BR %Od " or " %Oe
207 The day of the month using the locale's alternative numeric symbols;
208 leading zeros are permitted but not required.
209 .TP
210 .B %OH
211 The hour (24-hour clock) using the locale's alternative numeric symbols.
212 .TP
213 .B %OI
214 The hour (12-hour clock) using the locale's alternative numeric symbols.
215 .TP
216 .B %Om
217 The month using the locale's alternative numeric symbols.
218 .TP
219 .B %OM
220 The minutes using the locale's alternative numeric symbols.
221 .TP
222 .B %OS
223 The seconds using the locale's alternative numeric symbols.
224 .TP
225 .B %OU
226 The week number of the year (Sunday as the first day of the week)
227 using the locale's alternative numeric symbols.
228 .TP
229 .B %Ow
230 The number of the weekday (Sunday=0) using the locale's alternative
231 numeric symbols.
232 .TP
233 .B %OW
234 The week number of the year (Monday as the first day of the week)
235 using the locale's alternative numeric symbols.
236 .TP
237 .B %Oy
238 The year (offset from %C) using the locale's alternative numeric symbols.
239 .LP
240 The broken-down time structure \fItm\fP is defined in \fI<time.h>\fP
241 as follows:
242 .sp
243 .in +0.5i
244 .nf
245 struct tm {
246 int tm_sec; /* seconds */
247 int tm_min; /* minutes */
248 int tm_hour; /* hours */
249 int tm_mday; /* day of the month */
250 int tm_mon; /* month */
251 int tm_year; /* year */
252 int tm_wday; /* day of the week */
253 int tm_yday; /* day in the year */
254 int tm_isdst; /* daylight saving time */
255 };
256 .fi
257 .in -0.5i
258 .SH "RETURN VALUE"
259 The return value of the function is a pointer to the first character
260 not processed in this function call.
261 In case the input string
262 contains more characters than required by the format string the return
263 value points right after the last consumed input character.
264 In case
265 the whole input string is consumed the return value points to the null
266 byte at the end of the string.
267 If \fBstrptime\fP() fails to match all
268 of the format string and therefore an error occurred the function
269 returns NULL.
270 .SH "CONFORMING TO"
271 SUSv2, POSIX.1-2001.
272 .SH EXAMPLE
273 The following example demonstrates the use of \fBstrptime\fP()
274 and \fBstrftime\fP().
275 .sp
276 .nf
277 #include <stdio.h>
278 #include <time.h>
279
280 int
281 main(void)
282 {
283 struct tm tm;
284 char buf[255];
285
286 strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
287 strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
288 puts(buf);
289 return 0;
290 }
291 .fi
292 .SH "GNU EXTENSIONS"
293 For reasons of symmetry, glibc tries to support for
294 .BR strptime ()
295 the same format characters as for
296 .BR strftime ().
297 (In most cases the corresponding fields are parsed, but no field in \fItm\fP
298 is changed.)
299 This leads to
300 .TP
301 .B %F
302 Equivalent to \fB%Y-%m-%d\fP, the ISO 8601 date format.
303 .TP
304 .B %g
305 The year corresponding to the ISO week number, but without the century
306 (0-99).
307 .TP
308 .B %G
309 The year corresponding to the ISO week number. (For example, 1991.)
310 .TP
311 .B %u
312 The day of the week as a decimal number (1-7, where Monday = 1).
313 .TP
314 .B %V
315 The ISO 8601:1988 week number as a decimal number (1-53).
316 If the week (starting on Monday) containing 1 January has four or more days
317 in the new year, then it is considered week 1.
318 Otherwise, it is the last week
319 of the previous year, and the next week is week 1.
320 .TP
321 .B %z
322 An RFC-822/ISO 8601 standard time zone specification.
323 .TP
324 .B %Z
325 The timezone name.
326 .LP
327 Similarly, because of GNU extensions to \fIstrftime\fP(),
328 %k is accepted as a synonym for %H, and %l should be accepted
329 as a synonym for %I, and %P is accepted as a synonym for %p.
330 Finally
331 .TP
332 .B %s
333 The number of seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC.
334 Leap seconds are not counted unless leap second support is available.
335 .LP
336 The GNU libc implementation does not require whitespace between
337 two field descriptors.
338 .SH NOTES
339 .LP
340 In principle, this function does not initialize \fBtm\fP but
341 only stores the values specified.
342 This means that \fBtm\fP should be initialized before the call.
343 Details differ a bit between different Unix systems.
344 The GNU libc implementation does not touch those fields which are not
345 explicitly specified, except that it recomputes the
346 .IR tm_wday
347 and
348 .IR tm_yday
349 field if any of the year, month, or day elements changed.
350 .PP
351 This function is available since libc 4.6.8.
352 Linux libc4 and libc5 includes define the prototype unconditionally;
353 glibc2 includes provide a prototype only when _XOPEN_SOURCE or _GNU_SOURCE
354 are defined.
355 .PP
356 Before libc 5.4.13 whitespace (and the 'n' and 't' specifications)
357 was not handled, no 'E' and 'O' locale modifier characters were accepted,
358 and the 'C' specification was a synonym for the 'c' specification.
359 .PP
360 The 'y' (year in century) specification is taken to specify a year
361 in the 20th century by libc4 and libc5.
362 It is taken to be a year
363 in the range 1950-2049 by glibc 2.0.
364 It is taken to be a year in
365 1969-2068 since glibc 2.1.
366 .\" In libc4 and libc5 the code for %I is broken (fixed in glibc;
367 .\" %OI was fixed in glibc 2.2.4).
368 .SH "SEE ALSO"
369 .BR time (2),
370 .BR getdate (3),
371 .BR scanf (3),
372 .BR setlocale (3),
373 .BR strftime (3),
374 .BR feature_test_macros (7)