2 .\" Copyright 1993 Mitchum DSouza <m.dsouza@mrc-apu.cam.ac.uk>
4 .\" SPDX-License-Identifier: Linux-man-pages-copyleft
6 .\" Modified, jmv@lucifer.dorms.spbu.ru, 1999-11-08
7 .\" Modified, aeb, 2000-04-07
8 .\" Updated from glibc docs, C. Scott Ananian, 2001-08-25
9 .\" Modified, aeb, 2001-08-31
10 .\" Modified, wharms 2001-11-12, remark on white space and example
12 .TH strptime 3 (date) "Linux man-pages (unreleased)"
14 strptime \- convert a string representation of time to a time tm structure
17 .RI ( libc ", " \-lc )
20 .BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
23 .BI "char *strptime(const char *restrict " s ", const char *restrict " format ,
24 .BI " struct tm *restrict " tm );
29 function is the converse of
31 it converts the character string pointed to by
33 to values which are stored in the
35 structure pointed to by
37 using the format specified by
40 The broken-down time structure
48 is a character string that consists of field descriptors and text characters,
51 Each field descriptor consists of a
53 character followed by another character that specifies the replacement
54 for the field descriptor.
55 All other characters in the
57 string must have a matching character in the input string,
58 except for whitespace, which matches zero or more
59 whitespace characters in the input string.
60 There should be white\%space or other alphanumeric characters
61 between any two field descriptors.
65 function processes the input string from left
67 Each of the three possible input elements (whitespace,
68 literal, or format) are handled one after the other.
69 If the input cannot be matched to the format string, the function stops.
70 The remainder of the format and input strings are not processed.
72 The supported input field descriptors are listed below.
73 In case a text string (such as the name of a day of the week or a month name)
74 is to be matched, the comparison is case insensitive.
75 In case a number is to be matched, leading zeros are
76 permitted but not required.
84 The name of the day of the week according to the current locale,
85 in abbreviated form or the full name.
87 .BR %b " or " %B " or " %h
88 The month name according to the current locale,
89 in abbreviated form or the full name.
92 The date and time representation for the current locale.
95 The century number (0\[en]99).
98 The day of month (1\[en]31).
103 (This is the American style date, very confusing
104 to non-Americans, especially since
106 is widely used in Europe.
107 The ISO 8601 standard format is
114 The hour on a 12-hour clock (1\[en]12).
117 The day number in the year (1\[en]366).
120 The month number (1\[en]12).
123 The minute (0\[en]59).
126 Arbitrary whitespace.
129 The locale's equivalent of AM or PM.
130 (Note: there may be none.)
133 The 12-hour clock time (using the locale's AM or PM).
134 In the POSIX locale equivalent to
140 part of the current locale,
141 then the behavior is undefined.
148 The second (0\[en]60; 60 may occur for leap seconds;
149 earlier also 61 was allowed).
152 Arbitrary whitespace.
159 The week number with Sunday the first day of the week (0\[en]53).
160 The first Sunday of January is the first day of week 1.
163 The ordinal number of the day of the week (0\[en]6), with Sunday = 0.
166 The week number with Monday the first day of the week (0\[en]53).
167 The first Monday of January is the first day of week 1.
170 The date, using the locale's date format.
173 The time, using the locale's time format.
176 The year within century (0\[en]99).
177 When a century is not otherwise specified, values in the range 69\[en]99 refer
178 to years in the twentieth century (1969\[en]1999); values in the
179 range 00\[en]68 refer to years in the twenty-first century (2000\[en]2068).
182 The year, including century (for example, 1991).
184 Some field descriptors can be modified by the E or O modifier characters
185 to indicate that an alternative format or specification should be used.
187 alternative format or specification does not exist in the current locale, the
188 unmodified field descriptor is used.
190 The E modifier specifies that the input string may contain
191 alternative locale-dependent versions of the date and time representation:
194 The locale's alternative date and time representation.
197 The name of the base year (period) in the locale's alternative representation.
200 The locale's alternative date representation.
203 The locale's alternative time representation.
208 (year only) in the locale's alternative representation.
211 The full alternative year representation.
213 The O modifier specifies that the numerical input may be in an
214 alternative locale-dependent format:
217 The day of the month using the locale's alternative numeric symbols;
218 leading zeros are permitted but not required.
221 The hour (24-hour clock) using the locale's alternative numeric symbols.
224 The hour (12-hour clock) using the locale's alternative numeric symbols.
227 The month using the locale's alternative numeric symbols.
230 The minutes using the locale's alternative numeric symbols.
233 The seconds using the locale's alternative numeric symbols.
236 The week number of the year (Sunday as the first day of the week)
237 using the locale's alternative numeric symbols.
240 The ordinal number of the day of the week (Sunday=0),
241 using the locale's alternative numeric symbols.
244 The week number of the year (Monday as the first day of the week)
245 using the locale's alternative numeric symbols.
248 The year (offset from
250 using the locale's alternative numeric symbols.
252 The return value of the function is a pointer to the first character
253 not processed in this function call.
254 In case the input string
255 contains more characters than required by the format string, the return
256 value points right after the last consumed input character.
257 In case the whole input string is consumed,
258 the return value points to the null byte at the end of the string.
262 of the format string and therefore an error occurred, the function
265 For an explanation of the terms used in this section, see
273 Interface Attribute Value
276 T} Thread safety MT-Safe env locale
286 In principle, this function does not initialize
289 stores only the values specified.
292 should be initialized before the call.
293 Details differ a bit between different UNIX systems.
294 The glibc implementation does not touch those fields which are not
295 explicitly specified, except that it recomputes the
299 field if any of the year, month, or day elements changed.
301 .\" This function is available since libc 4.6.8.
302 .\" Linux libc4 and libc5 includes define the prototype unconditionally;
303 .\" glibc2 includes provide a prototype only when
309 .\" Before libc 5.4.13 whitespace
310 .\" (and the \[aq]n\[aq] and \[aq]t\[aq] specifications) was not handled,
311 .\" no \[aq]E\[aq] and \[aq]O\[aq] locale modifier characters were accepted,
312 .\" and the \[aq]C\[aq] specification was a synonym for the \[aq]c\[aq] specification.
314 The \[aq]y\[aq] (year in century) specification is taken to specify a year
315 .\" in the 20th century by libc4 and libc5.
316 .\" It is taken to be a year
317 in the range 1950\[en]2049 by glibc 2.0.
318 It is taken to be a year in
319 1969\[en]2068 since glibc 2.1.
320 .\" In libc4 and libc5 the code for %I is broken (fixed in glibc;
321 .\" %OI was fixed in glibc 2.2.4).
323 For reasons of symmetry, glibc tries to support for
325 the same format characters as for
327 (In most cases, the corresponding fields are parsed, but no field in
335 the ISO 8601 date format.
338 The year corresponding to the ISO week number, but without the century
342 The year corresponding to the ISO week number.
346 The day of the week as a decimal number (1\[en]7, where Monday = 1).
349 The ISO 8601:1988 week number as a decimal number (1\[en]53).
350 If the week (starting on Monday) containing 1 January has four or more days
351 in the new year, then it is considered week 1.
352 Otherwise, it is the last week
353 of the previous year, and the next week is week 1.
356 An RFC-822/ISO 8601 standard timezone specification.
361 Similarly, because of GNU extensions to
364 is accepted as a synonym for
373 is accepted as a synonym for
378 The number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
379 Leap seconds are not counted unless leap second support is available.
381 The glibc implementation does not require whitespace between
382 two field descriptors.
384 The following example demonstrates the use of
389 .\" SRC BEGIN (strptime.c)
391 #define _XOPEN_SOURCE
403 memset(&tm, 0, sizeof(tm));
404 strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
405 strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);