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/.
7 .\" The Institute of Electrical and Electronics Engineers and The Open
8 .\" Group, have given us permission to reprint portions of their
11 .\" In the following statement, the phrase ``this text'' refers to portions
12 .\" of the system documentation.
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.
25 .\" This notice shall appear on any product containing this material.
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.
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.
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]
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>
47 .TH STRPTIME 3C "Jun 27, 2014"
49 strptime, strptime_l \- date and time conversion
55 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
56 \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
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);
67 .SS "Non-zeroing Behavior"
70 \fBcc\fR [\fIflag\fR...] \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...]
73 \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR,
74 \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR);
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.
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
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"
97 The following conversion specifications are supported:
113 Day of week, using the locale's weekday names; either the abbreviated or full
114 name may be specified.
132 Month, using the locale's month names; either the abbreviated or full name may
151 Locale's appropriate date and time representation.
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.
175 Day of month [1,31]; leading zero is permitted but not required.
184 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
211 Hour (24-hour clock) [0,23]; leading zero is permitted but not required.
220 Hour (12-hour clock) [1,12]; leading zero is permitted but not required.
229 Day number of the year [1,366]; leading zeros are permitted but not required.
238 Month number [1,12]; leading zero is permitted but not required.
247 Minute [0-59]; leading zero is permitted but not required.
265 Locale's equivalent of either a.m. or p.m.
274 Appropriate time representation in the 12-hour clock format with \fB%p\fR.
283 Time as \fB%H\fR:\fB%M\fR.
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"
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.
324 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
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.
343 Weekday as a decimal number [0,6], with 0 representing Sunday.
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.
362 Locale's appropriate date representation.
371 Locale's appropriate time representation.
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
392 Year, including the century (for example, 1993).
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.
418 Locale's alternate appropriate date and time representation.
427 Name of the base year (era) in the locale's alternate representation.
436 Locale's alternate date representation.
445 Locale's alternate time representation.
454 Offset from \fB%EC\fR (year only) in the locale's alternate representation.
463 Full alternate year representation.
472 Day of the month using the locale's alternate numeric symbols.
490 Hour (24-hour clock) using the locale's alternate numeric symbols.
499 Hour (12-hour clock) using the locale's alternate numeric symbols.
508 Month using the locale's alternate numeric symbols.
517 Minutes using the locale's alternate numeric symbols.
526 Seconds using the locale's alternate numeric symbols.
535 Week number of the year (Sunday as the first day of the week) using the
536 locale's alternate numeric symbols.
545 Number of the weekday (Sunday=0) using the locale's alternate numeric symbols.
554 Week number of the year (Monday as the first day of the week) using the
555 locale's alternate numeric symbols.
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:
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.
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:
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.
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
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
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.
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.
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.
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.
693 Upon successful completion, \fBstrptime()\fR returns a pointer to the character
694 following the last character parsed. Otherwise, a null pointer is returned.
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.
711 See \fBattributes\fR(5) for descriptions of the following attributes:
716 ATTRIBUTE TYPE ATTRIBUTE VALUE
720 Interface Stability See below.
724 Standard See \fBstandards\fR(5) for \fBstrptime()\fR.
728 The \fBstrptime()\fR function is Standard. The \fBstrptime_l()\fR function
732 \fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C),
734 \fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBuselocale\fR(3C),
735 \fBattributes\fR(5), \fBenviron\fR(5),