Unleashed v1.4
[unleashed.git] / share / man / man3c / strptime.3c
blob6d889e9fc11b624aa295c42ed501694274bd91c5
1 .\"
2 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for
3 .\" permission to reproduce portions of its copyrighted documentation.
4 .\" Original documentation from The Open Group can be obtained online at
5 .\" http://www.opengroup.org/bookstore/.
6 .\"
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
9 .\" documentation.
10 .\"
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
13 .\"
14 .\" Portions of this text are reprinted and reproduced in electronic form
15 .\" in the SunOS Reference Manual, from IEEE Std 1003.1, 2004 Edition,
16 .\" Standard for Information Technology -- Portable Operating System
17 .\" Interface (POSIX), The Open Group Base Specifications Issue 6,
18 .\" Copyright (C) 2001-2004 by the Institute of Electrical and Electronics
19 .\" Engineers, Inc and The Open Group.  In the event of any discrepancy
20 .\" between these versions and the original IEEE and The Open Group
21 .\" Standard, the original IEEE and The Open Group Standard is the referee
22 .\" document.  The original Standard can be obtained online at
23 .\" http://www.opengroup.org/unix/online.html.
24 .\"
25 .\" This notice shall appear on any product containing this material.
26 .\"
27 .\" The contents of this file are subject to the terms of the
28 .\" Common Development and Distribution License (the "License").
29 .\" You may not use this file except in compliance with the License.
30 .\"
31 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
32 .\" or http://www.opensolaris.org/os/licensing.
33 .\" See the License for the specific language governing permissions
34 .\" and limitations under the License.
35 .\"
36 .\" When distributing Covered Code, include this CDDL HEADER in each
37 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
38 .\" If applicable, add the following below this CDDL HEADER, with the
39 .\" fields enclosed by brackets "[]" replaced with your own identifying
40 .\" information: Portions Copyright [yyyy] [name of copyright owner]
41 .\"
42 .\"
43 .\" Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
44 .\" Portions Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
45 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
46 .\"
47 .TH STRPTIME 3C "Jun 27, 2014"
48 .SH NAME
49 strptime, strptime_l \- date and time conversion
50 .SH SYNOPSIS
51 .LP
52 .nf
53 #include <time.h>
55 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
56      \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
57 .fi
58 .LP
59 .nf
60 #include <time.h>
61 #include <xlocale.h>
63 \fBchar *\fR\fBstrptime_l\fR(\fBconst char *restrict\fR \fIbuf\fR,
64      \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR,
65      \fBlocale_t\fR \fIloc\fR);
66 .fi
67 .SS "Non-zeroing Behavior"
68 .LP
69 .nf
70 \fBcc\fR [\fIflag\fR...]  \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...]
71 #include <time.h>
73 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
74      \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
75 .fi
77 .SH DESCRIPTION
78 .LP
79 The \fBstrptime()\fR function converts the character string pointed to by
80 \fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by
81 \fItm\fR, using the format specified by \fIformat\fR. The \fBstrptime_l()\fR
82 function is identical to \fBstrptime()\fR except instead of acting in the
83 current locale, it acts in the locale specified by the argument \fIloc\fR.
84 .LP
85 The \fIformat\fR argument is composed of zero or more conversion
86 specifications. Each conversion specification is composed of a "%" (percent)
87 character followed by one or two conversion characters which specify the
88 replacement required. One or more white space characters (as specified by
89 \fBisspace\fR(3C)) may precede or follow a conversion specification. There must
90 be white-space or other non-alphanumeric characters between any two conversion
91 specifications.
92 .LP
93 A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing
94 Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined.
95 .SS "Conversion Specifications"
96 .LP
97 The following conversion specifications are supported:
98 .sp
99 .ne 2
101 \fB\fB%%\fR\fR
103 .RS 6n
104 Same as \fB%\fR.
108 .ne 2
110 \fB\fB%a\fR\fR
112 .RS 6n
113 Day of week, using the locale's weekday names;  either the abbreviated or full
114 name may be specified.
118 .ne 2
120 \fB\fB%A\fR\fR
122 .RS 6n
123 Same as \fB%a\fR.
127 .ne 2
129 \fB\fB%b\fR\fR
131 .RS 6n
132 Month, using the locale's month names;  either the abbreviated or full name may
133 be specified.
137 .ne 2
139 \fB\fB%B\fR\fR
141 .RS 6n
142 Same as \fB%b\fR.
146 .ne 2
148 \fB\fB%c\fR\fR
150 .RS 6n
151 Locale's appropriate date and time representation.
155 .ne 2
157 \fB\fB%C\fR\fR
159 .RS 6n
160 Century number (the year divided by 100 and truncated to an integer as a
161 decimal number [1,99]); single digits are preceded by 0. If \fB%C\fR is used
162 without the \fB%y\fR specifier, \fBstrptime()\fR assumes the year offset is
163 zero in whichever century is specified.   Note the behavior of \fB%C\fR in the
164 absence of \fB%y\fR is not specified by any of the standards or specifications
165 described on the \fBstandards\fR(5) manual page, so portable applications
166 should not depend on it.  This behavior may change in a future release.
170 .ne 2
172 \fB\fB%d\fR\fR
174 .RS 6n
175 Day of month [1,31]; leading zero is permitted but not required.
179 .ne 2
181 \fB\fB%D\fR\fR
183 .RS 6n
184 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
188 .ne 2
190 \fB\fB%e\fR\fR
192 .RS 6n
193 Same as \fB%d\fR.
197 .ne 2
199 \fB\fB%h\fR\fR
201 .RS 6n
202 Same as \fB%b\fR.
206 .ne 2
208 \fB\fB%H\fR\fR
210 .RS 6n
211 Hour (24-hour clock) [0,23];  leading zero is permitted but not required.
215 .ne 2
217 \fB\fB%I\fR\fR
219 .RS 6n
220 Hour (12-hour clock) [1,12];  leading zero is permitted but not required.
224 .ne 2
226 \fB\fB%j\fR\fR
228 .RS 6n
229 Day number of the year [1,366];  leading zeros are permitted but not required.
233 .ne 2
235 \fB\fB%m\fR\fR
237 .RS 6n
238 Month number [1,12]; leading zero is permitted but not required.
242 .ne 2
244 \fB\fB%M\fR\fR
246 .RS 6n
247 Minute [0-59]; leading zero is permitted but not required.
251 .ne 2
253 \fB\fB%n\fR\fR
255 .RS 6n
256 Any white space.
260 .ne 2
262 \fB\fB%p\fR\fR
264 .RS 6n
265 Locale's equivalent of either a.m. or p.m.
269 .ne 2
271 \fB\fB%r\fR\fR
273 .RS 6n
274 Appropriate time representation in the 12-hour clock format with \fB%p\fR.
278 .ne 2
280 \fB\fB%R\fR\fR
282 .RS 6n
283 Time as \fB%H\fR:\fB%M\fR.
286 .SS "SUSv3"
288 .ne 2
290 \fB\fB%S\fR\fR
292 .RS 6n
293 Seconds [0,60]; leading zero is permitted but not required. The range of values
294 is [00,60] rather than [00,59] to allow for the occasional leap second.
297 .SS "Default and other standards"
299 .ne 2
301 \fB\fB%S\fR\fR
303 .RS 6n
304 Seconds [0,61]; leading zero is permitted but not required. The range of values
305 is [00,61] rather than [00,59] to allow for the occasional leap second and even
306 more occasional double leap second.
310 .ne 2
312 \fB\fB%t\fR\fR
314 .RS 6n
315 Any white space.
319 .ne 2
321 \fB\fB%T\fR\fR
323 .RS 6n
324 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
328 .ne 2
330 \fB\fB%U\fR\fR
332 .RS 6n
333 Week number of the year as a decimal number [0,53], with Sunday as the first
334 day of the week; leading zero is permitted but not required.
338 .ne 2
340 \fB\fB%w\fR\fR
342 .RS 6n
343 Weekday as a decimal number [0,6], with 0 representing Sunday.
347 .ne 2
349 \fB\fB%W\fR\fR
351 .RS 6n
352 Week number of the year as a decimal number [0,53], with Monday as the first
353 day of the week; leading zero is permitted but not required.
357 .ne 2
359 \fB\fB%x\fR\fR
361 .RS 6n
362 Locale's appropriate date representation.
366 .ne 2
368 \fB\fB%X\fR\fR
370 .RS 6n
371 Locale's appropriate time representation.
375 .ne 2
377 \fB\fB%y\fR\fR
379 .RS 6n
380 Year within century. When a century is not otherwise specified, values in the
381 range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive);
382 values in the range 00-68 refer to years in the twenty-first century (2000 to
383 2068 inclusive).
387 .ne 2
389 \fB\fB%Y\fR\fR
391 .RS 6n
392 Year, including the century (for example, 1993).
396 .ne 2
398 \fB\fB%Z\fR\fR
400 .RS 6n
401 Time zone name or no characters if no time zone exists.
404 .SS "Modified Conversion Specifications"
406 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
407 modifier characters to indicate that an alternate format or specification
408 should be used rather than the one normally used by the unmodified
409 specification. If the alternate format or specification does not exist in the
410 current locale, the behavior will be as if the unmodified conversion
411 specification were used.
413 .ne 2
415 \fB\fB%Ec\fR\fR
417 .RS 7n
418 Locale's alternate appropriate date and time representation.
422 .ne 2
424 \fB\fB%EC\fR\fR
426 .RS 7n
427 Name of the base year (era) in the locale's alternate representation.
431 .ne 2
433 \fB\fB%Ex\fR\fR
435 .RS 7n
436 Locale's alternate date representation.
440 .ne 2
442 \fB\fB%EX\fR\fR
444 .RS 7n
445 Locale's alternate time representation.
449 .ne 2
451 \fB\fB%Ey\fR\fR
453 .RS 7n
454 Offset from \fB%EC\fR (year only) in the locale's alternate representation.
458 .ne 2
460 \fB\fB%EY\fR\fR
462 .RS 7n
463 Full alternate year representation.
467 .ne 2
469 \fB\fB%Od\fR\fR
471 .RS 7n
472 Day of the month using the locale's alternate numeric symbols.
476 .ne 2
478 \fB\fB%Oe\fR\fR
480 .RS 7n
481 Same as \fB%Od\fR.
485 .ne 2
487 \fB\fB%OH\fR\fR
489 .RS 7n
490 Hour (24-hour clock) using the locale's alternate numeric symbols.
494 .ne 2
496 \fB\fB%OI\fR\fR
498 .RS 7n
499 Hour (12-hour clock) using the locale's alternate numeric symbols.
503 .ne 2
505 \fB\fB%Om\fR\fR
507 .RS 7n
508 Month using the locale's alternate numeric symbols.
512 .ne 2
514 \fB\fB%OM\fR\fR
516 .RS 7n
517 Minutes using the locale's alternate numeric symbols.
521 .ne 2
523 \fB\fB%OS\fR\fR
525 .RS 7n
526 Seconds using the locale's alternate numeric symbols.
530 .ne 2
532 \fB\fB%OU\fR\fR
534 .RS 7n
535 Week number of the year (Sunday as the first day of the week) using the
536 locale's alternate numeric symbols.
540 .ne 2
542 \fB\fB%Ow\fR\fR
544 .RS 7n
545 Number of the weekday (Sunday=0) using the  locale's alternate numeric symbols.
549 .ne 2
551 \fB\fB%OW\fR\fR
553 .RS 7n
554 Week number of the year (Monday as the first day of the week) using the
555 locale's alternate numeric symbols.
559 .ne 2
561 \fB\fB%Oy\fR\fR
563 .RS 7n
564 Year (offset from \fB%C\fR) in the locale's alternate  representation and using
565 the locale's alternate numeric symbols.
568 .SS "General Specifications"
570 A conversion specification that is an ordinary character is executed by
571 scanning the next character from the buffer. If the character scanned from the
572 buffer differs from the one comprising the specification, the specification
573 fails, and the differing and subsequent characters remain unscanned.
576 A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space
577 characters or any combination is executed by scanning up to the first character
578 that is not white space (which remains unscanned), or until no more characters
579 can be scanned.  White space is defined by \fBisspace\fR(3C).
581 Any other conversion specification is executed by scanning characters until a
582 character matching the next specification is scanned, or until no more
583 characters can be scanned. These characters, except the one matching the next
584 specification, are then compared to the locale values associated with the
585 conversion specifier.  If a match is found, values for the appropriate
586 \fItm\fR structure members are set to values corresponding to the locale
587 information. If no match is found,  \fBstrptime()\fR fails and no more
588 characters are scanned.
591 The month names, weekday names, era names, and alternate numeric symbols can
592 consist of any combination of upper and lower case letters.  The user can
593 request that the input date or time specification be in a specific language by
594 setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C).
595 .SS "Non-zeroing Behavior"
597 In addition to the behavior described above by various standards, the Solaris
598 implementation of \fBstrptime()\fR provides the following extensions. These may
599 change at any time in the future.  Portable applications should not depend on
600 these extended features:
601 .RS +4
603 .ie t \(bu
604 .el o
605 If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on
606 entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated
607 with the specifiers in the format string.
609 .RS +4
611 .ie t \(bu
612 .el o
613 If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the
614 \fBtm struct\fR on entry.  Additionally, for some specifiers, \fBstrptime()\fR
615 will use some values in the input \fBtm struct\fR to recalculate the date and
616 re-assign the appropriate members of the \fBtm struct\fR.
619 The following describes extended features regardless of whether
620 \fB_STRPTIME_DONTZERO\fR is defined or not defined:
621 .RS +4
623 .ie t \(bu
624 .el o
625 If \fB%j\fR is specified, \fBtm_yday\fR is set;  if year is given, and if month
626 and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR,
627 \fBtm_mday\fR, and \fBtm_year\fR.
629 .RS +4
631 .ie t \(bu
632 .el o
633 If \fB%U\fR or \fB%W\fR is specified and if weekday and year are given and
634 month and day of month are not given, \fBstrptime()\fR calculates and sets
635 \fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR.
638 The following describes extended features when \fB_STRPTIME_DONTZERO\fR is not
639 defined:
640 .RS +4
642 .ie t \(bu
643 .el o
644 If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fRassumes
645 0 as the year offset, then calculates the year, and assigns \fBtm_year\fR.
648 The following describes extended features when \fB_STRPTIME_DONTZERO\fR is
649 defined:
650 .RS +4
652 .ie t \(bu
653 .el o
654 If \fB%C\fR is specified and \fB%y\fR is not specified, \fBstrptime()\fR
655 assumes the year offset of the year value of the \fBtm_year\fR member of the
656 input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR.
658 .RS +4
660 .ie t \(bu
661 .el o
662 If \fB%j\fR is specified and neither \fB%y\fR, \fB%Y\fR, nor \fB%C\fR are
663 specified, and neither month nor day of month are specified, \fBstrptime()\fR
664 assumes the year value given by the value of the \fBtm_year\fR field of the
665 input \fBtm struct\fR.  Then, in addition to setting \fBtm_yday\fR,
666 \fBstrptime()\fR uses day-of-year and year values to calculate the month and
667 day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR.
669 .RS +4
671 .ie t \(bu
672 .el o
673 If \fB%U\fR or \fB%W\fR is specified, and if weekday and/or year are not given,
674 and month and day of month are not given, \fBstrptime()\fR will assume the
675 weekday value and/or the year value as the value of the \fBtm_wday\fR field
676 and/or \fBtm_year\fR field of the input \fBtm struct\fR.  Then,
677 \fBstrptime()\fR will calculate the month and day-of-month and assign
678 \fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR.
680 .RS +4
682 .ie t \(bu
683 .el o
684 If \fB%p\fR is specified and if hour is not specified, \fBstrptime()\fR will
685 reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR
686 input is p.m. and the input \fBtm_hour\fR value is between 0 - 11,
687 \fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR.  If the
688 \fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23,
689 \fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR.
691 .SH RETURN VALUES
693 Upon successful completion, \fBstrptime()\fR returns a pointer to the character
694 following the last character parsed. Otherwise, a null pointer is returned.
695 .SH USAGE
697 Several "same as" formats, and the special processing of white-space characters
698 are provided in order to ease the use of identical  \fIformat\fR strings for
699 \fBstrftime\fR(3C) and \fBstrptime()\fR.
701 The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR,
702 and \fBtm_mday\fR when given incomplete input.  This allows the \fBstruct tm\fR
703 created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a
704 \fBtime_t\fR value for dates and times that are representable by a
705 \fBtime_t\fR.  As an example, since \fBmktime()\fR ignores \fBtm_yday\fR,
706 \fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling
707 in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a
708 month and day within month.
709 .SH ATTRIBUTES
711 See \fBattributes\fR(5) for descriptions of the following attributes:
713 box;
714 c | c
715 l | l .
716 ATTRIBUTE TYPE  ATTRIBUTE VALUE
718 CSI     Enabled
720 Interface Stability     See below.
722 MT-Level        MT-Safe
724 Standard        See \fBstandards\fR(5) for \fBstrptime()\fR.
728 The \fBstrptime()\fR function is Standard.  The \fBstrptime_l()\fR function
729 is Uncommitted.
730 .SH SEE ALSO
732 \fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C),
733 \fBnewlocale\fR(3C),
734 \fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBuselocale\fR(3C),
735 \fBattributes\fR(5), \fBenviron\fR(5),
736 \fBstandards\fR(5)