mount_setattr.2: ffix
[man-pages.git] / man3 / strptime.3
blobd6595d4bf95cfdc9c5739c8a8ca03443ec0235cf
1 .\" Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified, jmv@lucifer.dorms.spbu.ru, 1999-11-08
26 .\" Modified, aeb, 2000-04-07
27 .\" Updated from glibc docs, C. Scott Ananian, 2001-08-25
28 .\" Modified, aeb, 2001-08-31
29 .\" Modified, wharms 2001-11-12, remark on white space and example
30 .\"
31 .TH STRPTIME 3 2021-03-22 "GNU" "Linux Programmer's Manual"
32 .SH NAME
33 strptime \- convert a string representation of time to a time tm structure
34 .SH SYNOPSIS
35 .nf
36 .BR "#define _XOPEN_SOURCE" "       /* See feature_test_macros(7) */"
37 .B #include <time.h>
38 .PP
39 .BI "char *strptime(const char *restrict " s ", const char *restrict " format ,
40 .BI "               struct tm *restrict " tm );
41 .fi
42 .SH DESCRIPTION
43 The
44 .BR strptime ()
45 function is the converse of
46 .BR strftime (3);
47 it converts the character string pointed to by
48 .I s
49 to values which are stored in the
50 "broken-down time"
51 structure pointed to by
52 .IR tm ,
53 using the format specified by
54 .IR format .
55 .PP
56 The broken-down time structure
57 .I tm
58 is defined in
59 .IR <time.h>
60 as follows:
61 .PP
62 .in +4n
63 .EX
64 struct tm {
65     int tm_sec;    /* Seconds (0\-60) */
66     int tm_min;    /* Minutes (0\-59) */
67     int tm_hour;   /* Hours (0\-23) */
68     int tm_mday;   /* Day of the month (1\-31) */
69     int tm_mon;    /* Month (0\-11) */
70     int tm_year;   /* Year \- 1900 */
71     int tm_wday;   /* Day of the week (0\-6, Sunday = 0) */
72     int tm_yday;   /* Day in the year (0\-365, 1 Jan = 0) */
73     int tm_isdst;  /* Daylight saving time */
75 .EE
76 .in
77 .PP
78 For more details on the
79 .I tm
80 structure, see
81 .BR ctime (3).
82 .PP
83 The
84 .I format
85 argument
86 is a character string that consists of field descriptors and text characters,
87 reminiscent of
88 .BR scanf (3).
89 Each field descriptor consists of a
90 .B %
91 character followed by another character that specifies the replacement
92 for the field descriptor.
93 All other characters in the
94 .I format
95 string must have a matching character in the input string,
96 except for whitespace, which matches zero or more
97 whitespace characters in the input string.
98 There should be white\%space or other alphanumeric characters
99 between any two field descriptors.
102 .BR strptime ()
103 function processes the input string from left
104 to right.
105 Each of the three possible input elements (whitespace,
106 literal, or format) are handled one after the other.
107 If the input cannot be matched to the format string, the function stops.
108 The remainder of the format and input strings are not processed.
110 The supported input field descriptors are listed below.
111 In case a text string (such as the name of a day of the week or a month name)
112 is to be matched, the comparison is case insensitive.
113 In case a number is to be matched, leading zeros are
114 permitted but not required.
116 .B %%
118 .B %
119 character.
121 .BR %a " or " %A
122 The name of the day of the week according to the current locale,
123 in abbreviated form or the full name.
125 .BR %b " or " %B " or " %h
126 The month name according to the current locale,
127 in abbreviated form or the full name.
129 .B %c
130 The date and time representation for the current locale.
132 .B %C
133 The century number (0\(en99).
135 .BR %d " or " %e
136 The day of month (1\(en31).
138 .B %D
139 Equivalent to
140 .BR %m/%d/%y .
141 (This is the American style date, very confusing
142 to non-Americans, especially since
143 .B %d/%m/%y
144 is widely used in Europe.
145 The ISO 8601 standard format is
146 .BR %Y\-%m\-%d .)
148 .B %H
149 The hour (0\(en23).
151 .B %I
152 The hour on a 12-hour clock (1\(en12).
154 .B %j
155 The day number in the year (1\(en366).
157 .B %m
158 The month number (1\(en12).
160 .B %M
161 The minute (0\(en59).
163 .B %n
164 Arbitrary whitespace.
166 .B %p
167 The locale's equivalent of AM or PM.
168 (Note: there may be none.)
170 .B %r
171 The 12-hour clock time (using the locale's AM or PM).
172 In the POSIX locale equivalent to
173 .BR "%I:%M:%S %p" .
175 .I t_fmt_ampm
176 is empty in the
177 .B LC_TIME
178 part of the current locale,
179 then the behavior is undefined.
181 .B %R
182 Equivalent to
183 .BR %H:%M .
185 .B %S
186 The second (0\(en60; 60 may occur for leap seconds;
187 earlier also 61 was allowed).
189 .B %t
190 Arbitrary whitespace.
192 .B %T
193 Equivalent to
194 .BR %H:%M:%S .
196 .B %U
197 The week number with Sunday the first day of the week (0\(en53).
198 The first Sunday of January is the first day of week 1.
200 .B %w
201 The ordinal number of the day of the week (0\(en6), with Sunday = 0.
203 .B %W
204 The week number with Monday the first day of the week (0\(en53).
205 The first Monday of January is the first day of week 1.
207 .B %x
208 The date, using the locale's date format.
210 .B %X
211 The time, using the locale's time format.
213 .B %y
214 The year within century (0\(en99).
215 When a century is not otherwise specified, values in the range 69\(en99 refer
216 to years in the twentieth century (1969\(en1999); values in the
217 range 00\(en68 refer to years in the twenty-first century (2000\(en2068).
219 .B %Y
220 The year, including century (for example, 1991).
222 Some field descriptors can be modified by the E or O modifier characters
223 to indicate that an alternative format or specification should be used.
224 If the
225 alternative format or specification does not exist in the current locale, the
226 unmodified field descriptor is used.
228 The E modifier specifies that the input string may contain
229 alternative locale-dependent versions of the date and time representation:
231 .B %Ec
232 The locale's alternative date and time representation.
234 .B %EC
235 The name of the base year (period) in the locale's alternative representation.
237 .B %Ex
238 The locale's alternative date representation.
240 .B %EX
241 The locale's alternative time representation.
243 .B %Ey
244 The offset from
245 .B %EC
246 (year only) in the locale's alternative representation.
248 .B %EY
249 The full alternative year representation.
251 The O modifier specifies that the numerical input may be in an
252 alternative locale-dependent format:
254 .BR %Od " or " %Oe
255 The day of the month using the locale's alternative numeric symbols;
256 leading zeros are permitted but not required.
258 .B %OH
259 The hour (24-hour clock) using the locale's alternative numeric symbols.
261 .B %OI
262 The hour (12-hour clock) using the locale's alternative numeric symbols.
264 .B %Om
265 The month using the locale's alternative numeric symbols.
267 .B %OM
268 The minutes using the locale's alternative numeric symbols.
270 .B %OS
271 The seconds using the locale's alternative numeric symbols.
273 .B %OU
274 The week number of the year (Sunday as the first day of the week)
275 using the locale's alternative numeric symbols.
277 .B %Ow
278 The ordinal number of the day of the week (Sunday=0),
279  using the locale's alternative numeric symbols.
281 .B %OW
282 The week number of the year (Monday as the first day of the week)
283 using the locale's alternative numeric symbols.
285 .B %Oy
286 The year (offset from
287 .BR %C )
288 using the locale's alternative numeric symbols.
289 .SH RETURN VALUE
290 The return value of the function is a pointer to the first character
291 not processed in this function call.
292 In case the input string
293 contains more characters than required by the format string, the return
294 value points right after the last consumed input character.
295 In case the whole input string is consumed,
296 the return value points to the null byte at the end of the string.
298 .BR strptime ()
299 fails to match all
300 of the format string and therefore an error occurred, the function
301 returns NULL.
302 .SH ATTRIBUTES
303 For an explanation of the terms used in this section, see
304 .BR attributes (7).
305 .ad l
308 allbox;
309 lbx lb lb
310 l l l.
311 Interface       Attribute       Value
313 .BR strptime ()
314 T}      Thread safety   MT-Safe env locale
318 .sp 1
319 .SH CONFORMING TO
320 POSIX.1-2001, POSIX.1-2008, SUSv2.
321 .SH NOTES
322 In principle, this function does not initialize
323 .I tm
325 stores only the values specified.
326 This means that
327 .I tm
328 should be initialized before the call.
329 Details differ a bit between different UNIX systems.
330 The glibc implementation does not touch those fields which are not
331 explicitly specified, except that it recomputes the
332 .I tm_wday
334 .I tm_yday
335 field if any of the year, month, or day elements changed.
336 .\" .PP
337 .\" This function is available since libc 4.6.8.
338 .\" Linux libc4 and libc5 includes define the prototype unconditionally;
339 .\" glibc2 includes provide a prototype only when
340 .\" .B _XOPEN_SOURCE
341 .\" or
342 .\" .B _GNU_SOURCE
343 .\" are defined.
344 .\" .PP
345 .\" Before libc 5.4.13 whitespace
346 .\" (and the \(aqn\(aq and \(aqt\(aq specifications) was not handled,
347 .\" no \(aqE\(aq and \(aqO\(aq locale modifier characters were accepted,
348 .\" and the \(aqC\(aq specification was a synonym for the \(aqc\(aq specification.
350 The \(aqy\(aq (year in century) specification is taken to specify a year
351 .\" in the 20th century by libc4 and libc5.
352 .\" It is taken to be a year
353 in the range 1950\(en2049 by glibc 2.0.
354 It is taken to be a year in
355 1969\(en2068 since glibc 2.1.
356 .\" In libc4 and libc5 the code for %I is broken (fixed in glibc;
357 .\" %OI was fixed in glibc 2.2.4).
358 .SS Glibc notes
359 For reasons of symmetry, glibc tries to support for
360 .BR strptime ()
361 the same format characters as for
362 .BR strftime (3).
363 (In most cases, the corresponding fields are parsed, but no field in
364 .I tm
365 is changed.)
366 This leads to
368 .B %F
369 Equivalent to
370 .BR %Y\-%m\-%d ,
371 the ISO 8601 date format.
373 .B %g
374 The year corresponding to the ISO week number, but without the century
375 (0\(en99).
377 .B %G
378 The year corresponding to the ISO week number.
379 (For example, 1991.)
381 .B %u
382 The day of the week as a decimal number (1\(en7, where Monday = 1).
384 .B %V
385 The ISO 8601:1988 week number as a decimal number (1\(en53).
386 If the week (starting on Monday) containing 1 January has four or more days
387 in the new year, then it is considered week 1.
388 Otherwise, it is the last week
389 of the previous year, and the next week is week 1.
391 .B %z
392 An RFC-822/ISO 8601 standard timezone specification.
394 .B %Z
395 The timezone name.
397 Similarly, because of GNU extensions to
398 .BR strftime (3),
399 .B %k
400 is accepted as a synonym for
401 .BR %H ,
403 .B %l
404 should be accepted
405 as a synonym for
406 .BR %I ,
408 .B %P
409 is accepted as a synonym for
410 .BR %p .
411 Finally
413 .B %s
414 The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
415 Leap seconds are not counted unless leap second support is available.
417 The glibc implementation does not require whitespace between
418 two field descriptors.
419 .SH EXAMPLES
420 The following example demonstrates the use of
421 .BR strptime ()
423 .BR strftime (3).
426 #define _XOPEN_SOURCE
427 #include <stdio.h>
428 #include <stdlib.h>
429 #include <string.h>
430 #include <time.h>
433 main(void)
435     struct tm tm;
436     char buf[255];
438     memset(&tm, 0, sizeof(tm));
439     strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
440     strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
441     puts(buf);
442     exit(EXIT_SUCCESS);
445 .SH SEE ALSO
446 .BR time (2),
447 .BR getdate (3),
448 .BR scanf (3),
449 .BR setlocale (3),
450 .BR strftime (3)