'\" te .\" Copyright (c) 1992, X/Open Company Limited. All Rights Reserved. .\" Portions Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH strptime 3C "21 Dec 2010" "SunOS 5.11" "Standard C Library Functions" .SH NAME strptime \- date and time conversion .SH SYNOPSIS .LP .nf #include \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR, \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR); .fi .SS "Non-zeroing Behavior" .LP .nf \fBcc\fR [\fIflag\fR...] \fIfile\fR... \fB-D_STRPTIME_DONTZERO\fR [\fIlibrary\fR...] #include \fBchar *\fR\fBstrptime\fR(\fBconst char *restrict\fR \fIbuf\fR, \fBconst char *restrict\fR \fIformat\fR, \fBstruct tm *restrict\fR \fItm\fR); .fi .SH DESCRIPTION .sp .LP The \fBstrptime()\fR function converts the character string pointed to by \fIbuf\fR to values which are stored in the \fBtm\fR structure pointed to by \fItm\fR, using the format specified by \fIformat\fR. .sp .LP The \fIformat\fR argument is composed of zero or more conversion specifications. Each conversion specification is composed of a "%" (percent) character followed by one or two conversion characters which specify the replacement required. One or more white space characters (as specified by \fBisspace\fR(3C)) may precede or follow a conversion specification. There must be white-space or other non-alphanumeric characters between any two conversion specifications. .sp .LP A non-zeroing version of \fBstrptime()\fR, described below under \fBNon-zeroing Behavior\fR, is provided if \fB_STRPTIME_DONTZERO\fR is defined. .SS "Conversion Specifications" .sp .LP The following conversion specifications are supported: .sp .ne 2 .mk .na \fB\fB%%\fR\fR .ad .RS 6n .rt Same as \fB%\fR. .RE .sp .ne 2 .mk .na \fB\fB%a\fR\fR .ad .RS 6n .rt Day of week, using the locale's weekday names; either the abbreviated or full name may be specified. .RE .sp .ne 2 .mk .na \fB\fB%A\fR\fR .ad .RS 6n .rt Same as \fB%a\fR. .RE .sp .ne 2 .mk .na \fB\fB%b\fR\fR .ad .RS 6n .rt Month, using the locale's month names; either the abbreviated or full name may be specified. .RE .sp .ne 2 .mk .na \fB\fB%B\fR\fR .ad .RS 6n .rt Same as \fB%b\fR. .RE .sp .ne 2 .mk .na \fB\fB%c\fR\fR .ad .RS 6n .rt Locale's appropriate date and time representation. .RE .sp .ne 2 .mk .na \fB\fB%C\fR\fR .ad .RS 6n .rt Century number (the year divided by 100 and truncated to an integer as a decimal number [1,99]); single digits are preceded by 0. If \fB%C\fR is used without the \fB%y\fR specifier, \fBstrptime()\fR assumes the year offset is zero in whichever century is specified. Note the behavior of \fB%C\fR in the absence of \fB%y\fR is not specified by any of the standards or specifications described on the \fBstandards\fR(5) manual page, so portable applications should not depend on it. This behavior may change in a future release. .RE .sp .ne 2 .mk .na \fB\fB%d\fR\fR .ad .RS 6n .rt Day of month [1,31]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%D\fR\fR .ad .RS 6n .rt Date as \fB%m\fR/\fB%d\fR/\fB%y\fR. .RE .sp .ne 2 .mk .na \fB\fB%e\fR\fR .ad .RS 6n .rt Same as \fB%d\fR. .RE .sp .ne 2 .mk .na \fB\fB%F\fR\fR .ad .RS 6n .rt Equivalent to \fB%Y\fR-\fB%m\fR-\fB%d\fR (the ISO 8601:2004 standard date in extended format). .RE .sp .ne 2 .mk .na \fB\fB%g\fR\fR .ad .RS 6n .rt Week-based year within century [00,99]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%G\fR\fR .ad .RS 6n .rt Week-based year, including the century [0000,9999]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%h\fR\fR .ad .RS 6n .rt Same as \fB%b\fR. .RE .sp .ne 2 .mk .na \fB\fB%H\fR\fR .ad .RS 6n .rt Hour (24-hour clock) [0,23]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%I\fR\fR .ad .RS 6n .rt Hour (12-hour clock) [1,12]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%j\fR\fR .ad .RS 6n .rt Day number of the year [1,366]; leading zeros are permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%k\fR\fR .ad .RS 6n .rt Same as \fB%H\fR. .RE .sp .ne 2 .mk .na \fB\fB%l\fR\fR .ad .RS 6n .rt Same as \fB%I\fR. .RE .sp .ne 2 .mk .na \fB\fB%m\fR\fR .ad .RS 6n .rt Month number [1,12]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%M\fR\fR .ad .RS 6n .rt Minute [0-59]; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%n\fR\fR .ad .RS 6n .rt Any white space. .RE .sp .ne 2 .mk .na \fB\fB%p\fR\fR .ad .RS 6n .rt Locale's equivalent of either a.m. or p.m. .RE .sp .ne 2 .mk .na \fB\fB%P\fR\fR .ad .RS 6n .rt Locale's equivalent of either a.m. or p.m. in case-insensitive manner. .RE .sp .ne 2 .mk .na \fB\fB%r\fR\fR .ad .RS 6n .rt Appropriate time representation in the 12-hour clock format with \fB%p\fR. .RE .sp .ne 2 .mk .na \fB\fB%R\fR\fR .ad .RS 6n .rt Time as \fB%H\fR:\fB%M\fR. .RE .SS "SUSv3" .sp .ne 2 .mk .na \fB\fB%S\fR\fR .ad .RS 6n .rt Seconds [0,60]; leading zero is permitted but not required. The range of values is [00,60] rather than [00,59] to allow for the occasional leap second. .RE .SS "Default and other standards" .sp .ne 2 .mk .na \fB\fB%S\fR\fR .ad .RS 6n .rt Seconds [0,61]; leading zero is permitted but not required. The range of values is [00,61] rather than [00,59] to allow for the occasional leap second and even more occasional double leap second. .RE .sp .ne 2 .mk .na \fB\fB%t\fR\fR .ad .RS 6n .rt Any white space. .RE .sp .ne 2 .mk .na \fB\fB%T\fR\fR .ad .RS 6n .rt Time as \fB%H\fR:\fB%M\fR:\fB%S\fR. .RE .sp .ne 2 .mk .na \fB\fB%u\fR\fR .ad .RS 6n .rt Weekday as a decimal number [1,7], with 1 representing Monday. .RE .sp .ne 2 .mk .na \fB\fB%U\fR\fR .ad .RS 6n .rt Week number of the year as a decimal number [0,53], with Sunday as the first day of the week; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%V\fR\fR .ad .RS 6n .rt The ISO 8601 week number as a decimal number [01,53]. In the ISO 8601 week-based system, weeks begin on a Monday and week 1 of the year is the week that includes both January 4th and the first Thursday of the year. If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year. .RE .sp .ne 2 .mk .na \fB\fB%w\fR\fR .ad .RS 6n .rt Weekday as a decimal number [0,6], with 0 representing Sunday. .RE .sp .ne 2 .mk .na \fB\fB%W\fR\fR .ad .RS 6n .rt Week number of the year as a decimal number [0,53], with Monday as the first day of the week; leading zero is permitted but not required. .RE .sp .ne 2 .mk .na \fB\fB%x\fR\fR .ad .RS 6n .rt Locale's appropriate date representation. .RE .sp .ne 2 .mk .na \fB\fB%X\fR\fR .ad .RS 6n .rt Locale's appropriate time representation. .RE .sp .ne 2 .mk .na \fB\fB%y\fR\fR .ad .RS 6n .rt Year within century. When a century is not otherwise specified, values in the range 69-99 refer to years in the twentieth century (1969 to 1999 inclusive); values in the range 00-68 refer to years in the twenty-first century (2000 to 2068 inclusive). .RE .sp .ne 2 .mk .na \fB\fB%Y\fR\fR .ad .RS 6n .rt Year, including the century (for example, 1993). .RE .sp .ne 2 .mk .na \fB\fB%z\fR\fR .ad .RS 6n .rt Offset from UTC in ISO 8601:2004 standard basic format (+\fBhhmm\fR or -\fBhhmm\fR), or no characters if no time zone is determinable. .RE .sp .ne 2 .mk .na \fB\fB%Z\fR\fR .ad .RS 6n .rt Time zone name or no characters if no time zone exists. .RE .SS "Modified Conversion Specifications" .sp .LP Some conversion specifications can be modified by the \fBE\fR and \fBO\fR modifier characters to indicate that an alternate format or specification should be used rather than the one normally used by the unmodified specification. If the alternate format or specification does not exist in the current locale, the behavior will be as if the unmodified conversion specification were used. .sp .ne 2 .mk .na \fB\fB%Ec\fR\fR .ad .RS 7n .rt Locale's alternate appropriate date and time representation. .RE .sp .ne 2 .mk .na \fB\fB%EC\fR\fR .ad .RS 7n .rt Name of the base year (era) in the locale's alternate representation. .RE .sp .ne 2 .mk .na \fB\fB%Ex\fR\fR .ad .RS 7n .rt Locale's alternate date representation. .RE .sp .ne 2 .mk .na \fB\fB%EX\fR\fR .ad .RS 7n .rt Locale's alternate time representation. .RE .sp .ne 2 .mk .na \fB\fB%Ey\fR\fR .ad .RS 7n .rt Offset from \fB%EC\fR (year only) in the locale's alternate representation. .RE .sp .ne 2 .mk .na \fB\fB%EY\fR\fR .ad .RS 7n .rt Full alternate year representation. .RE .sp .ne 2 .mk .na \fB\fB%Od\fR\fR .ad .RS 7n .rt Day of the month using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%Oe\fR\fR .ad .RS 7n .rt Same as \fB%Od\fR. .RE .sp .ne 2 .mk .na \fB\fB%OH\fR\fR .ad .RS 7n .rt Hour (24-hour clock) using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%OI\fR\fR .ad .RS 7n .rt Hour (12-hour clock) using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%Om\fR\fR .ad .RS 7n .rt Month using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%OM\fR\fR .ad .RS 7n .rt Minutes using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%OS\fR\fR .ad .RS 7n .rt Seconds using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%OU\fR\fR .ad .RS 7n .rt Week number of the year (Sunday as the first day of the week) using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%Ow\fR\fR .ad .RS 7n .rt Number of the weekday (Sunday=0) using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%OW\fR\fR .ad .RS 7n .rt Week number of the year (Monday as the first day of the week) using the locale's alternate numeric symbols. .RE .sp .ne 2 .mk .na \fB\fB%Oy\fR\fR .ad .RS 7n .rt Year (offset from \fB%C\fR) in the locale's alternate representation and using the locale's alternate numeric symbols. .RE .SS "General Specifications" .sp .LP A conversion specification that is an ordinary character is executed by scanning the next character from the buffer. If the character scanned from the buffer differs from the one comprising the specification, the specification fails, and the differing and subsequent characters remain unscanned. .sp .LP A series of specifications composed of \fB%n\fR, \fB%t\fR, white-space characters or any combination is executed by scanning up to the first character that is not white space (which remains unscanned), or until no more characters can be scanned. White space is defined by \fBisspace\fR(3C). .sp .LP Any other conversion specification is executed by scanning characters until a character matching the next specification is scanned, or until no more characters can be scanned. These characters, except the one matching the next specification, are then compared to the locale values associated with the conversion specifier. If a match is found, values for the appropriate \fItm\fR structure members are set to values corresponding to the locale information. If no match is found, \fBstrptime()\fR fails and no more characters are scanned. .sp .LP The month names, weekday names, era names, and alternate numeric symbols can consist of any combination of upper and lower case letters. The user can request that the input date or time specification be in a specific language by setting the \fBLC_TIME\fR category using \fBsetlocale\fR(3C). .SS "Non-zeroing Behavior" .sp .LP In addition to the behavior described above by various standards, the Solaris implementation of \fBstrptime()\fR provides the following extensions. These may change at any time in the future. Portable applications should not depend on these extended features: .RS +4 .TP .ie t \(bu .el o If \fB_STRPTIME_DONTZERO\fR is not defined, the \fBtm struct\fR is zeroed on entry and \fBstrptime()\fR updates the fields of the \fBtm struct\fR associated with the specifiers in the format string. .RE .RS +4 .TP .ie t \(bu .el o If \fB_STRPTIME_DONTZERO\fR is defined, \fBstrptime()\fR does not zero the \fBtm struct\fR on entry. Additionally, for some specifiers, \fBstrptime()\fR will use some values in the input \fBtm struct\fR to recalculate the date and re-assign the appropriate members of the \fBtm struct\fR. .RE .sp .LP The following describes extended features regardless of whether \fB_STRPTIME_DONTZERO\fR is defined or not defined: .RS +4 .TP .ie t \(bu .el o If \fB%j\fR is specified, \fBtm_yday\fR is set; if year is given, and if month and day are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR, \fBtm_mday\fR, and \fBtm_year\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fB%U\fR, \fB%V\fR, or \fB%W\fR is specified and if weekday and year are given and month and day of month are not given, \fBstrptime()\fR calculates and sets \fBtm_mon\fR, \fBtm_mday\fR, \fBtm_wday\fR, and \fBtm_year\fR. .RE .sp .LP The following describes extended features when \fB_STRPTIME_DONTZERO\fR is not defined: .RS +4 .TP .ie t \(bu .el o If \fB%C\fR is specified and neither \fB%g\fR nor \fB%y\fR is specified, \fBstrptime()\fR assumes 0 as the year offset, then calculates the year and assigns \fBtm_year\fR. .RE .sp .LP The following describes extended features when \fB_STRPTIME_DONTZERO\fR is defined: .RS +4 .TP .ie t \(bu .el o If \fB%C\fR is specified and neither \fB%g\fR nor \fB%y\fR is specified, \fBstrptime()\fR assumes the year offset of the year value of the \fBtm_year\fR member of the input \fBtm struct\fR, then calculates the year and assigns \fBtm_year\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fB%j\fR is specified and neither \fB%C\fR, \fB%g\fR, \fB%G\fR, \fB%y\fR, nor \fB%Y\fR is specified, and neither month nor day of month is specified, \fBstrptime()\fR assumes the year value given by the value of the \fBtm_year\fR field of the input \fBtm struct\fR. Then, in addition to setting \fBtm_yday\fR, \fBstrptime()\fR uses day-of-year and year values to calculate the month and day-of-month, and assigns \fBtm_month\fR and \fBtm_mday\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fB%U\fR, \fB%V\fR, or \fB%W\fR is specified, and if weekday and/or year are not given, and month and day of month are not given, \fBstrptime()\fR will assume the weekday value and/or the year value as the value of the \fBtm_wday\fR field and/or \fBtm_year\fR field of the input \fBtm struct\fR. Then, \fBstrptime()\fR will calculate the month and day-of-month and assign \fBtm_month\fR, \fBtm_mday\fR, and/or \fBtm_year\fR. .RE .RS +4 .TP .ie t \(bu .el o If \fB%p\fR or \fB%P\fR is specified and if hour is not specified, \fBstrptime()\fR will reference, and if needed, update the \fBtm_hour\fR member. If the \fBam_pm\fR input is p.m. and the input \fBtm_hour\fR value is between 0 - 11, \fBstrptime()\fR will add 12 hours and update \fBtm_hour\fR. If the \fBam_pm\fR input is a.m. and input \fBtm_hour\fR value is between 12 - 23, \fBstrptime()\fR will subtract 12 hours and update \fBtm_hour\fR. .RE .SH RETURN VALUES .sp .LP Upon successful completion, \fBstrptime()\fR returns a pointer to the character following the last character parsed. Otherwise, a null pointer is returned. .SH USAGE .sp .LP Several "same as" formats, and the special processing of white-space characters are provided in order to ease the use of identical \fIformat\fR strings for \fBstrftime\fR(3C) and \fBstrptime()\fR. .sp .LP The \fBstrptime()\fR function tries to calculate \fBtm_year\fR, \fBtm_mon\fR, and \fBtm_mday\fR when given incomplete input. This allows the \fBstruct tm\fR created by \fBstrptime()\fR to be passed to \fBmktime\fR(3C) to produce a \fBtime_t\fR value for dates and times that are representable by a \fBtime_t\fR. As an example, since \fBmktime()\fR ignores \fBtm_yday\fR, \fBstrptime()\fR calculates \fBtm_mon\fR and \fBtm_mday\fR as well as filling in \fBtm_yday\fR when \fB%j\fR is specified without otherwise specifying a month and day within month. .SH ATTRIBUTES .sp .LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ CSIEnabled _ Interface StabilityCommitted _ MT-LevelMT-Safe _ StandardSee \fBstandards\fR(5). .TE .SH SEE ALSO .sp .LP \fBctime\fR(3C), \fBgetdate\fR(3C), \fBisspace\fR(3C), \fBmktime\fR(3C), \fBsetlocale\fR(3C), \fBstrftime\fR(3C), \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)