OSDN Git Service

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