strftime, cftime, ascftime - convert date and time to string
size_t strftime (char *s, size_t maxsize, const char *format,
const struct tm *timeptr);
int cftime (char *s, char *format, const time_t *clock);
int ascftime (char *s, const char *format, const struct tm
strftime, ascftime, and cftime place characters into the array pointed to
by s as controlled by the string pointed to by format. The format string
consists of zero or more directives and ordinary characters. All
ordinary characters (including the terminating null character) are copied
unchanged into the array. For strftime, no more than maxsize characters
are placed into the array.
If format is (char *)0, then the locale's default format is used. For
strftime the default format is the same as "%KC", for cftime and ascftime
the default format is the same as "%KC". cftime and ascftime first try
to use the value of the environment variable CFTIME, and if that is
undefined or empty, the default format is used.
Each directive is replaced by appropriate characters as described in the
following list. The appropriate characters are determined by the LC_TIME
category of the program's locale and by the values contained in the
structure pointed to by timeptr for strftime and ascftime, and by the
time represented by clock for cftime.
%% same as %
%a locale's abbreviated weekday name
%A locale's full weekday name
%b locale's abbreviated month name
%B locale's full month name
%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 [00-99]
%d day of month ( 01 - 31 )
%D date as %m/%d/%y
%e day of month (1-31; single digits are preceded by a blank)
%h locale's abbreviated month name.
%H hour ( 00 - 23 )
%I hour ( 01 - 12 )
%j day number of year ( 001 - 366 )
%KC locale's appropriate date and time representation
%m month number ( 01 - 12 )
%M minute ( 00 - 59 )
%n same as new-line
%p locale's equivalent of either AM or PM
%r locale's 12-hour time representation, default %I:%M:%S [AM|PM]
%R time as %H:%M
%S seconds ( 00 - 61 ), allows for leap seconds
%t same as a tab
%T time as %H:%M:%S
%U week number of year ( 00 - 53 ), Sunday is the first day of
%w weekday number ( 0 - 6 ), Sunday = 0
%W week number of year ( 00 - 53 ), Monday is the first day of
%x locale's appropriate date representation
%X locale's appropriate time representation
%y year within century ( 00 - 99 )
%Y year as ccyy ( e.g. 1986)
%Z time zone name or no characters if no time zone exists
The difference between %U and %W lies in which day is counted as the
first of the week. Week number 01 is the first week in January starting
with a Sunday for %U or a Monday for %W. Week number 00 contains those
days before the first Sunday or Monday in January for %U and %W,
strftime, cftime, and ascftime return the number of characters placed
into the array pointed to by s not including the terminating null
character. (If more than maxsize characters would have been placed into
the array, strftime returns zero and the array content is indeterminate.
If strftime, cftime, or ascftime overrun the size of the array, the
behavior is undefined.)
Selecting the Output's Language
By default, the output of strftime, cftime, and ascftime appear in U.S.
English. The user can request that the output of strftime, cftime, or
ascftime be in a specific language by setting the locale for category
LC_TIME in setlocale.
Timezone [Toc] [Back]
The timezone is taken from the environment variable TZ [see ctime(3C) for
a description of TZ].
The example illustrates the use of strftime. It shows what the string in
str would look like if the structure pointed to by tmptr contains the
values corresponding to Thursday, August 28, 1986 at 12:44:36 in New
strftime (str, strsize, "%A %b %d %j", tmptr)
This results in str containing "Thursday Aug 28 240".
/usr/lib/locale/locale<b>/LC_TIME - file containing locale-specific date and
time(2), ctime(3C), getenv(3C), setlocale(3C), strftime(4), timezone(4),
cftime and ascftime are obsolete. strftime should be used instead.
PPPPaaaaggggeeee 3333 [ Back ]