1STRPTIME(3P) POSIX Programmer's Manual STRPTIME(3P)
2
3
4
6 This manual page is part of the POSIX Programmer's Manual. The Linux
7 implementation of this interface may differ (consult the corresponding
8 Linux manual page for details of Linux behavior), or the interface may
9 not be implemented on Linux.
10
12 strptime - date and time conversion
13
15 #include <time.h>
16
17 char *strptime(const char *restrict buf, const char *restrict format,
18 struct tm *restrict tm);
19
20
22 The strptime() function shall convert the character string pointed to
23 by buf to values which are stored in the tm structure pointed to by tm,
24 using the format specified by format.
25
26 The format is composed of zero or more directives. Each directive is
27 composed of one of the following: one or more white-space characters
28 (as specified by isspace()); an ordinary character (neither '%' nor a
29 white-space character); or a conversion specification. Each conversion
30 specification is composed of a '%' character followed by a conversion
31 character which specifies the replacement required. The application
32 shall ensure that there is white-space or other non-alphanumeric char‐
33 acters between any two conversion specifications. The following conver‐
34 sion specifications are supported:
35
36 %a The day of the week, using the locale's weekday names; either
37 the abbreviated or full name may be specified.
38
39 %A Equivalent to %a .
40
41 %b The month, using the locale's month names; either the abbrevi‐
42 ated or full name may be specified.
43
44 %B Equivalent to %b .
45
46 %c Replaced by the locale's appropriate date and time representa‐
47 tion.
48
49 %C The century number [00,99]; leading zeros are permitted but not
50 required.
51
52 %d The day of the month [01,31]; leading zeros are permitted but
53 not required.
54
55 %D The date as %m / %d / %y .
56
57 %e Equivalent to %d .
58
59 %h Equivalent to %b .
60
61 %H The hour (24-hour clock) [00,23]; leading zeros are permitted
62 but not required.
63
64 %I The hour (12-hour clock) [01,12]; leading zeros are permitted
65 but not required.
66
67 %j The day number of the year [001,366]; leading zeros are permit‐
68 ted but not required.
69
70 %m The month number [01,12]; leading zeros are permitted but not
71 required.
72
73 %M The minute [00,59]; leading zeros are permitted but not
74 required.
75
76 %n Any white space.
77
78 %p The locale's equivalent of a.m or p.m.
79
80 %r 12-hour clock time using the AM/PM notation if t_fmt_ampm is not
81 an empty string in the LC_TIME portion of the current locale; in
82 the POSIX locale, this shall be equivalent to %I : %M : %S %p .
83
84 %R The time as %H : %M .
85
86 %S The seconds [00,60]; leading zeros are permitted but not
87 required.
88
89 %t Any white space.
90
91 %T The time as %H : %M : %S .
92
93 %U The week number of the year (Sunday as the first day of the
94 week) as a decimal number [00,53]; leading zeros are permitted
95 but not required.
96
97 %w The weekday as a decimal number [0,6], with 0 representing Sun‐
98 day; leading zeros are permitted but not required.
99
100 %W The week number of the year (Monday as the first day of the
101 week) as a decimal number [00,53]; leading zeros are permitted
102 but not required.
103
104 %x The date, using the locale's date format.
105
106 %X The time, using the locale's time format.
107
108 %y The year within century. When a century is not otherwise speci‐
109 fied, values in the range [69,99] shall refer to years 1969 to
110 1999 inclusive, and values in the range [00,68] shall refer to
111 years 2000 to 2068 inclusive; leading zeros shall be permitted
112 but shall not be required.
113
114 Note:
115 It is expected that in a future version of IEEE Std 1003.1-2001
116 the default century inferred from a 2-digit year will change.
117 (This would apply to all commands accepting a 2-digit year as
118 input.)
119
120
121 %Y The year, including the century (for example, 1988).
122
123 %% Replaced by % .
124
125
126 Modified Conversion Specifiers
127 Some conversion specifiers can be modified by the E and O modifier
128 characters to indicate that an alternative format or specification
129 should be used rather than the one normally used by the unmodified con‐
130 version specifier. If the alternative format or specification does not
131 exist in the current locale, the behavior shall be as if the unmodified
132 conversion specification were used.
133
134 %Ec The locale's alternative appropriate date and time representa‐
135 tion.
136
137 %EC The name of the base year (period) in the locale's alternative
138 representation.
139
140 %Ex The locale's alternative date representation.
141
142 %EX The locale's alternative time representation.
143
144 %Ey The offset from %EC (year only) in the locale's alternative rep‐
145 resentation.
146
147 %EY The full alternative year representation.
148
149 %Od The day of the month using the locale's alternative numeric sym‐
150 bols; leading zeros are permitted but not required.
151
152 %Oe Equivalent to %Od .
153
154 %OH The hour (24-hour clock) using the locale's alternative numeric
155 symbols.
156
157 %OI The hour (12-hour clock) using the locale's alternative numeric
158 symbols.
159
160 %Om The month using the locale's alternative numeric symbols.
161
162 %OM The minutes using the locale's alternative numeric symbols.
163
164 %OS The seconds using the locale's alternative numeric symbols.
165
166 %OU The week number of the year (Sunday as the first day of the
167 week) using the locale's alternative numeric symbols.
168
169 %Ow The number of the weekday (Sunday=0) using the locale's alterna‐
170 tive numeric symbols.
171
172 %OW The week number of the year (Monday as the first day of the
173 week) using the locale's alternative numeric symbols.
174
175 %Oy The year (offset from %C ) using the locale's alternative
176 numeric symbols.
177
178
179 A conversion specification composed of white-space characters is exe‐
180 cuted by scanning input up to the first character that is not white-
181 space (which remains unscanned), or until no more characters can be
182 scanned.
183
184 A conversion specification that is an ordinary character is executed by
185 scanning the next character from the buffer. If the character scanned
186 from the buffer differs from the one comprising the directive, the
187 directive fails, and the differing and subsequent characters remain
188 unscanned.
189
190 A series of conversion specifications composed of %n, %t, white-space
191 characters, or any combination is executed by scanning up to the first
192 character that is not white space (which remains unscanned), or until
193 no more characters can be scanned.
194
195 Any other conversion specification is executed by scanning characters
196 until a character matching the next directive is scanned, or until no
197 more characters can be scanned. These characters, except the one match‐
198 ing the next directive, are then compared to the locale values associ‐
199 ated with the conversion specifier. If a match is found, values for the
200 appropriate tm structure members are set to values corresponding to the
201 locale information. Case is ignored when matching items in buf such as
202 month or weekday names. If no match is found, strptime() fails and no
203 more characters are scanned.
204
206 Upon successful completion, strptime() shall return a pointer to the
207 character following the last character parsed. Otherwise, a null
208 pointer shall be returned.
209
211 No errors are defined.
212
213 The following sections are informative.
214
216 None.
217
219 Several "equivalent to" formats and the special processing of white-
220 space characters are provided in order to ease the use of identical
221 format strings for strftime() and strptime().
222
223 Applications should use %Y (4-digit years) in preference to %y (2-digit
224 years).
225
226 It is unspecified whether multiple calls to strptime() using the same
227 tm structure will update the current contents of the structure or over‐
228 write all contents of the structure. Conforming applications should
229 make a single call to strptime() with a format and all data needed to
230 completely specify the date and time being converted.
231
233 None.
234
236 The strptime() function is expected to be mandatory in the next version
237 of this volume of IEEE Std 1003.1-2001.
238
240 scanf(), strftime(), time(), the Base Definitions volume of
241 IEEE Std 1003.1-2001, <time.h>
242
244 Portions of this text are reprinted and reproduced in electronic form
245 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
246 -- Portable Operating System Interface (POSIX), The Open Group Base
247 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
248 Electrical and Electronics Engineers, Inc and The Open Group. In the
249 event of any discrepancy between this version and the original IEEE and
250 The Open Group Standard, the original IEEE and The Open Group Standard
251 is the referee document. The original Standard can be obtained online
252 at http://www.opengroup.org/unix/online.html .
253
254
255
256IEEE/The Open Group 2003 STRPTIME(3P)