1 .\" Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
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.
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.
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
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
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
31 .TH STRPTIME 3 2021-03-22 "GNU" "Linux Programmer's Manual"
33 strptime \- convert a string representation of time to a time tm structure
36 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
39 .BI "char *strptime(const char *restrict " s ", const char *restrict " format ,
40 .BI " struct tm *restrict " tm );
45 function is the converse of
47 it converts the character string pointed to by
49 to values which are stored in the
51 structure pointed to by
53 using the format specified by
56 The broken-down time structure
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 */
78 For more details on the
86 is a character string that consists of field descriptors and text characters,
89 Each field descriptor consists of a
91 character followed by another character that specifies the replacement
92 for the field descriptor.
93 All other characters in the
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.
103 function processes the input string from left
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.
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.
130 The date and time representation for the current locale.
133 The century number (0\(en99).
136 The day of month (1\(en31).
141 (This is the American style date, very confusing
142 to non-Americans, especially since
144 is widely used in Europe.
145 The ISO 8601 standard format is
152 The hour on a 12-hour clock (1\(en12).
155 The day number in the year (1\(en366).
158 The month number (1\(en12).
161 The minute (0\(en59).
164 Arbitrary whitespace.
167 The locale's equivalent of AM or PM.
168 (Note: there may be none.)
171 The 12-hour clock time (using the locale's AM or PM).
172 In the POSIX locale equivalent to
178 part of the current locale,
179 then the behavior is undefined.
186 The second (0\(en60; 60 may occur for leap seconds;
187 earlier also 61 was allowed).
190 Arbitrary whitespace.
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.
201 The ordinal number of the day of the week (0\(en6), with Sunday = 0.
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.
208 The date, using the locale's date format.
211 The time, using the locale's time format.
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).
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.
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:
232 The locale's alternative date and time representation.
235 The name of the base year (period) in the locale's alternative representation.
238 The locale's alternative date representation.
241 The locale's alternative time representation.
246 (year only) in the locale's alternative representation.
249 The full alternative year representation.
251 The O modifier specifies that the numerical input may be in an
252 alternative locale-dependent format:
255 The day of the month using the locale's alternative numeric symbols;
256 leading zeros are permitted but not required.
259 The hour (24-hour clock) using the locale's alternative numeric symbols.
262 The hour (12-hour clock) using the locale's alternative numeric symbols.
265 The month using the locale's alternative numeric symbols.
268 The minutes using the locale's alternative numeric symbols.
271 The seconds using the locale's alternative numeric symbols.
274 The week number of the year (Sunday as the first day of the week)
275 using the locale's alternative numeric symbols.
278 The ordinal number of the day of the week (Sunday=0),
279 using the locale's alternative numeric symbols.
282 The week number of the year (Monday as the first day of the week)
283 using the locale's alternative numeric symbols.
286 The year (offset from
288 using the locale's alternative numeric symbols.
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.
300 of the format string and therefore an error occurred, the function
303 For an explanation of the terms used in this section, see
311 Interface Attribute Value
314 T} Thread safety MT-Safe env locale
320 POSIX.1-2001, POSIX.1-2008, SUSv2.
322 In principle, this function does not initialize
325 stores only the values specified.
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
335 field if any of the year, month, or day elements changed.
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
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).
359 For reasons of symmetry, glibc tries to support for
361 the same format characters as for
363 (In most cases, the corresponding fields are parsed, but no field in
371 the ISO 8601 date format.
374 The year corresponding to the ISO week number, but without the century
378 The year corresponding to the ISO week number.
382 The day of the week as a decimal number (1\(en7, where Monday = 1).
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.
392 An RFC-822/ISO 8601 standard timezone specification.
397 Similarly, because of GNU extensions to
400 is accepted as a synonym for
409 is accepted as a synonym for
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.
420 The following example demonstrates the use of
426 #define _XOPEN_SOURCE
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);