STRFTIME
Section: C Library Functions (3)
Index
Return to Main Contents
NAME
strftime - generate formatted time information
SYNOPSIS
#include <sys/types.h>
#include <time.h>
size_t strftime(char *s, size_t maxsize, const char *format,
const struct tm *timeptr);
DESCRIPTION
The following description is transcribed verbatim from the January 18, 1999
draft standard for ISO C.
This draft is essentially identical in technical content
to the final version of the standard.
``The
strftime
function places characters into the array pointed to by
s
as controlled by the string pointed to by
format.
The format shall be a multibyte character sequence, beginning and ending in
its initial shift state.
The
format
string consists of zero or more conversion specifiers and ordinary
multibyte characters. A conversion specifier consists of a
%
character, possibly followed by an
E
or
O
modifier character (described below),
followed by a character that determines the behavior of the
conversion specifier.
All ordinary multibyte characters (including the terminating null
character) are copied unchanged into the array.
If copying takes place between objects that overlap the behavior is undefined.
No more than
maxsize
characters are placed into the array.
``Each conversion specifier is replaced by appropriate characters as described
in the following list.
The appropriate characters are determined by the
LC_TIME
category of the current locale and by the values
of zero or more members of the broken-down time
structure pointed to by
timeptr,
as specified by brackets in the description.
If any of the specified values is outside the normal range, the characters
stored are unspecified.''
- %a
-
is replaced by the locale's abbreviated weekday name.
- %A
-
is replaced by the locale's full weekday name.
- %b
-
is replaced by the locale's abbreviated month name.
- %B
-
is replaced by the locale's full month name.
- %c
-
is replaced by the locale's appropriate date and time representation.
(This is
%A %B %d %T %Y
in the "C"
locale.)
- %C
-
is replaced by the year divided by 100 and truncated to an integer,
as a decimal number
(00-99).
- %d
-
is replaced by the day of the month as a decimal number
(01-31).
- %D
-
is equivalent to
%m/%d/%y.
- %e
-
is replaced by the day of the month as a decimal number
(1-31);
a single digit is preceded by a space.
- %F
-
is equivalent to
%Y-%m-%d
(the ISO 8601 date format).
- %g
-
is replaced by the year without century of the ISO week number
as a decimal number
(00-99).
- %G
-
is replaced by the year with century of the ISO week number
as a decimal number.
- %h
-
is equivalent to
%b.
- %H
-
is replaced by the hour (24-hour clock) as a decimal number
(00-23).
- %I
-
is replaced by the hour (12-hour clock) as a decimal number
(01-12).
- %j
-
is replaced by the day of the year as a decimal number
(001-366).
- %m
-
is replaced by the month as a decimal number
(01-12).
- %M
-
is replaced by the minute as a decimal number
(00-59).
- %n
-
is replaced with a newline character (ASCII LF).
- %p
-
is replaced by the locale's equivalent of the AM/PM designations associated
with a 12-hour clock.
- %r
-
is replaced by the locale's 12-hour clock time.
(This is
%I:%M:%S %p
in the "C"
locale.)
- %R
-
is equivalent to
%H:%M.
- %S
-
is replaced by the second as a decimal number
(00-60).
- %t
-
is replaced with a TAB character.
- %T
-
is equivalent to
%H:%M:%S.
- %u
-
is replaced by the ISO 8601 weekday as a decimal number
[1 (Monday)-7].
- %U
-
is replaced by the week number of the year (the first Sunday as the first
day of week 1) as a decimal number
(00-53).
- %V
-
is replaced by the ISO 8601 week number of the year (the first Monday as the first
day of week 1) as a decimal number
(01-53).
- %w
-
is replaced by the weekday as a decimal number
[0 (Sunday)-6].
- %W
-
is replaced by the week number of the year (the first Monday as the first
day of week 1) as a decimal number
(00-53).
- %x
-
is replaced by the locale's appropriate date representation.
(This is
%A %B %d %Y
in the "C"
locale.)
- %X
-
is replaced by the locale's appropriate time representation.
(This is
%T
in the "C"
locale.)
- %y
-
is replaced by the year without century as a decimal number
(00-99).
- %Y
-
is replaced by the year with century as a decimal number.
- %z
-
The timezone offset in a +HHMM format (e.g. the format necessary to
produce RFC-822/RFC-1036 date headers).
- %Z
-
is replaced by the time zone name or abbreviation, or by no characters if
no time zone is determinable.
- %%
-
is replaced by
%.
If a conversion specifier is not one of the above, the behavior is
undefined.
RETURNS
If the total number of resulting characters including the terminating null
character is not more than
maxsize,
the
strftime
function returns the number of characters placed into the array pointed to
by
s
not including the terminating null character.
Otherwise, zero is returned and the contents of the array are indeterminate.
ISO 8601
The method for determining the week number as specified by ISO 8601 is:
if the week containing January 1 has four or more days in the
new year, then it is week 1, otherwise it is the highest numbered
week of the previous year (52 or 53)
and the next week is week 1.
All days in a new year preceding the first Monday are considered to be
in week 0.
For example, January 1, 1993, is in week 53 of 1992. Thus, the year
of its ISO week number is 1992, even though its year is 1993.
Similarly, December 31, 1973, is in week 1 of 1974. Thus, the year
of its ISO week number is 1974, even though its year is 1973.
ALTERNATE REPRESENTATIONS
The alternate representations
%Ec,
%EC,
%Ex,
%EX,
%Ey,
%EY,
%Od,
%Oe,
%OH,
%OI,
%Om,
%OM,
%OS,
%Ou,
%OU,
%OV,
%Ow,
%OW,
and
%Oy
are recognized, but their normal representations are used.
NON-ISO EXTENSIONS
SunOS Extensions
If
SUNOS_EXT
is defined when the routine is compiled, then the following additional
conversions will be available.
These are borrowed from the SunOS version of
strftime.
- %k
-
is replaced by the hour (24-hour clock) as a decimal number
(0-23).
Single digit numbers are padded with a blank.
- %l
-
is replaced by the hour (12-hour clock) as a decimal number
(1-12).
Single digit numbers are padded with a blank.
HP/UX Extensions
If
HPUX_EXT
is defined when the routine is compiled, then the following additional
conversions will be available.
These are borrowed from the HP-UX version of
date.
- %N
-
The ``Emporer/Era'' name.
Typically, this is equivalent to the century
(same as
%C ).
- %o
-
The ``Emporer/Era'' year.
Typically, this is equivalent to the year
(same as
%y ).
VMS Extensions
If
VMS_EXT
is defined, then the following additional conversion is available:
- %v
-
The date in VMS format (e.g. 20-JUN-1991).
Other Extensions
If
HAVE_MKTIME
is defined, then this conversion is available:
- %s
-
The time in ``seconds since the Epoch,''
usually Midnight January 1, 1970, UTC.
SEE ALSO
time(2),
ctime(3),
localtime(3),
mktime(3),
tzset(3)
BUGS
This version does not handle multibyte characters or pay attention to the
setting of the
LC_TIME
environment variable.
The ``appropriate'' values used for
%c,
%x,
are
%X
are always those specified by the 1999 ISO C standard for the "C" locale.
CAVEATS
The pre-processor symbol
POSIX_SEMANTICS
is automatically defined, which forces the code to call
tzset(3)
whenever the
TZ
environment variable has changed.
If this routine will be used in an application that will not be changing
TZ,
then there may be some performance improvements by not defining
POSIX_SEMANTICS.
AUTHOR
Arnold Robbins <arnold@skeeve.com>
ACKNOWLEDGEMENTS
Thanks to Geoff Clare <gwc@root.co.uk> for helping debug earlier
versions of this routine, and for advice about POSIX semantics.
Additional thanks to Arthur David Olsen <ado@elsie.nci.nih.gov>
for some code improvements.
Thanks also to Tor Lillqvist <tml@tik.vtt.fi>
for code fixes to the ISO 8601 code.
Thanks to Hume Smith for pointing out a problem with the ISO 8601 code
and to Arthur David Olsen for further discussions.
Index
- NAME
-
- SYNOPSIS
-
- DESCRIPTION
-
- RETURNS
-
- ISO 8601
-
- ALTERNATE REPRESENTATIONS
-
- NON-ISO EXTENSIONS
-
- SunOS Extensions
-
- HP/UX Extensions
-
- VMS Extensions
-
- Other Extensions
-
- SEE ALSO
-
- BUGS
-
- CAVEATS
-
- AUTHOR
-
- ACKNOWLEDGEMENTS
-
This document was created by
man2html,
using the manual pages.
Time: 11:02:14 GMT, January 03, 2023