Standard C Library Functions strptime(3C)
NAME
strptime - date and time conversion
SYNOPSIS
#include
char *strptime(const char *restrict buf,
const char *restrict format, struct tm *restrict tm);
Non-zeroing Behavior
cc [flag...] file... -DSTRPTIMEDONTZERO [library...]
#include
char *strptime(const char *restrict buf,
const char *restrict format, struct tm *restrict tm);
DESCRIPTION
The strptime() function converts the character string
pointed to by buf to values which are stored in the tm
structure pointed to by tm, using the format specified by
format.
The format 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 isspace(3C))
may precede or follow a conversion specification. There must
be white-space or other non-alphanumeric characters between
any two conversion specifications.
A non-zeroing version of strptime(), described below under
Non-zeroing Behavior, is provided if STRPTIMEDONTZERO is
defined.
Conversion Specifications
The following conversion specifications are supported:
%% Same as %.
%a Day of week, using the locale's weekday names; either
the abbreviated or full name may be specified.
%A Same as %a.
SunOS 5.11 Last change: 27 Aug 2007 1
Standard C Library Functions strptime(3C)
%b Month, using the locale's month names; either the
abbreviated or full name may be specified.
%B Same as %b.
%c Locale's appropriate date and time representation.
%C 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 %C is used without the %y
specifier, strptime() assumes the year offset is zero
in whichever century is specified. Note the behavior
of %C in the absence of %y is not specified by any of
the standards or specifications described on the stan-
dards(5) manual page, so portable applications should
not depend on it. This behavior may change in a
future release.
%d Day of month [1,31]; leading zero is permitted but not
required.
%D Date as %m/%d/%y.
%e Same as %d.
%h Same as %b.
%H Hour (24-hour clock) [0,23]; leading zero is permit-
ted but not required.
%I Hour (12-hour clock) [1,12]; leading zero is permit-
ted but not required.
%j Day number of the year [1,366]; leading zeros are
permitted but not required.
%m Month number [1,12]; leading zero is permitted but not
required.
SunOS 5.11 Last change: 27 Aug 2007 2
Standard C Library Functions strptime(3C)
%M Minute [0-59]; leading zero is permitted but not
required.
%n Any white space.
%p Locale's equivalent of either a.m. or p.m.
%r Appropriate time representation in the 12-hour clock
format with %p.
%R Time as %H:%M.
SUSv3
%S 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.
Default and other standards
%S 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.
%t Any white space.
%T Time as %H:%M:%S.
%U 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.
%w Weekday as a decimal number [0,6], with 0 representing
Sunday.
%W 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.
%x Locale's appropriate date representation.
SunOS 5.11 Last change: 27 Aug 2007 3
Standard C Library Functions strptime(3C)
%X Locale's appropriate time representation.
%y 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).
%Y Year, including the century (for example, 1993).
%Z Time zone name or no characters if no time zone
exists.
Modified Conversion Specifications
Some conversion specifications can be modified by the E and
O 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 for-
mat or specification does not exist in the current locale,
the behavior will be as if the unmodified conversion specif-
ication were used.
%Ec Locale's alternate appropriate date and time
representation.
%EC Name of the base year (era) in the locale's alternate
representation.
%Ex Locale's alternate date representation.
%EX Locale's alternate time representation.
%Ey Offset from %EC (year only) in the locale's alternate
representation.
%EY Full alternate year representation.
%Od Day of the month using the locale's alternate numeric
symbols.
SunOS 5.11 Last change: 27 Aug 2007 4
Standard C Library Functions strptime(3C)
%Oe Same as %Od.
%OH Hour (24-hour clock) using the locale's alternate
numeric symbols.
%OI Hour (12-hour clock) using the locale's alternate
numeric symbols.
%Om Month using the locale's alternate numeric symbols.
%OM Minutes using the locale's alternate numeric symbols.
%OS Seconds using the locale's alternate numeric symbols.
%OU Week number of the year (Sunday as the first day of
the week) using the locale's alternate numeric sym-
bols.
%Ow Number of the weekday (Sunday=0) using the locale's
alternate numeric symbols.
%OW Week number of the year (Monday as the first day of
the week) using the locale's alternate numeric sym-
bols.
%Oy Year (offset from %C) in the locale's alternate
representation and using the locale's alternate
numeric symbols.
General Specifications
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.
A series of specifications composed of %n, %t, 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 isspace(3C).
SunOS 5.11 Last change: 27 Aug 2007 5
Standard C Library Functions strptime(3C)
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 specifi-
cation, are then compared to the locale values associated
with the conversion specifier. If a match is found, values
for the appropriate tm structure members are set to values
corresponding to the locale information. If no match is
found, strptime() fails and no more characters are scanned.
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 set-
ting the LCTIME category using setlocale(3C).
Non-zeroing Behavior
In addition to the behavior described above by various stan-
dards, the Solaris implementation of strptime() provides the
following extensions. These may change at any time in the
future. Portable applications should not depend on these
extended features:
o If STRPTIMEDONTZERO is not defined, the tm struct
is zeroed on entry and strptime() updates the
fields of the tm struct associated with the specif-
iers in the format string.
o If STRPTIMEDONTZERO is defined, strptime() does
not zero the tm struct on entry. Additionally, for
some specifiers, strptime() will use some values in
the input tm struct to recalculate the date and
re-assign the appropriate members of the tm struct.
The following describes extended features regardless of
whether STRPTIMEDONTZERO is defined or not defined:
o If %j is specified, tmyday is set; if year is
given, and if month and day are not given,
strptime() calculates and sets tmmon, tmmday, and
tmyear.
o If %U or %W is specified and if weekday and year
are given and month and day of month are not given,
strptime() calculates and sets tmmon, tmmday,
tmwday, and tmyear.
The following describes extended features when
STRPTIMEDONTZERO is not defined:
SunOS 5.11 Last change: 27 Aug 2007 6
Standard C Library Functions strptime(3C)
o If %C is specified and %y is not specified,
strptime()assumes 0 as the year offset, then calcu-
lates the year, and assigns tmyear.
The following describes extended features when
STRPTIMEDONTZERO is defined:
o If %C is specified and %y is not specified,
strptime() assumes the year offset of the year
value of the tmyear member of the input tm struct,
then calculates the year and assigns tmyear.
o If %j is specified and neither %y, %Y, nor %C are
specified, and neither month nor day of month are
specified, strptime() assumes the year value given
by the value of the tmyear field of the input tm
struct. Then, in addition to setting tmyday,
strptime() uses day-of-year and year values to cal-
culate the month and day-of-month, and assigns
tmmonth and tmmday.
o If %U or %W is specified, and if weekday and/or
year are not given, and month and day of month are
not given, strptime() will assume the weekday value
and/or the year value as the value of the tmwday
field and/or tmyear field of the input tm struct.
Then, strptime() will calculate the month and day-
of-month and assign tmmonth, tmmday, and/or
tmyear.
o If %p is specified and if hour is not specified,
strptime() will reference, and if needed, update
the tmhour member. If the ampm input is p.m. and
the input tmhour value is between 0 - 11,
strptime() will add 12 hours and update tmhour.
If the ampm input is a.m. and input tmhour value
is between 12 - 23, strptime() will subtract 12
hours and update tmhour.
RETURN VALUES
Upon successful completion, strptime() returns a pointer to
the character following the last character parsed. Other-
wise, a null pointer is returned.
USAGE
Several "same as" formats, and the special processing of
white-space characters are provided in order to ease the use
of identical format strings for strftime(3C) and
strptime().
SunOS 5.11 Last change: 27 Aug 2007 7
Standard C Library Functions strptime(3C)
The strptime() function tries to calculate tmyear, tmmon,
and tmmday when given incomplete input. This allows the
struct tm created by strptime() to be passed to mktime(3C)
to produce a timet value for dates and times that are
representable by a timet. As an example, since mktime()
ignores tmyday, strptime() calculates tmmon and tmmday as
well as filling in tmyday when %j is specified without oth-
erwise specifying a month and day within month.
ATRIBUTES
See attributes(5) for descriptions of the following attri-
butes:
ATRIBUTE TYPE ATRIBUTE VALUE
CSI Enabled
Interface Stability Committed
MT-Level MT-Safe
Standard See standards(5).
SEE ALSO
ctime(3C), getdate(3C), isspace(3C), mktime(3C),
setlocale(3C), strftime(3C), attributes(5), environ(5),
standards(5)
SunOS 5.11 Last change: 27 Aug 2007 8
|