strftime(3C) strftime(3C)
NAME
strftime, cftime, ascftime - convert date and time to string
SYNOPSIS
#include <time.h>
sizet strftime(char *s, sizet maxsize, const char *format,
const struct tm *timeptr);
int cftime(char *s, char *format, const timet *clock);
int ascftime(char *s, const char *format, const struct tm *timeptr);
DESCRIPTION
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 one or more conversion specifications and
ordinary characters. All ordinary characters, including the terminat-
ing 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 default format "%c" is used for
strftime(), and for cftime() and ascftime() the default format "%C"
[XPG3] is used. 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 conversion specification is replaced by appropriate characters as
described in the following list. The appropriate characters are deter-
mined by the LCTIME 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 (year divided by 100 and truncated to an integer
(00 - 99) [XPG4]
date and time representation as produced by date(1) [XPG3]
%d day of month (01 - 31)
Page 1 Reliant UNIX 5.44 Printed 11/98
strftime(3C) strftime(3C)
%D date as %m/%d/%y
%e day of month (1 - 31; single digits are preceded by a blank)
%f date and time representation as produced by date(1) [XPG4]
%h locale's abbreviated month name.
%H hour (00 - 23)
%I hour (01 - 12)
%j day number of year (001 - 366)
%m month number (01 - 12)
%M minute (00 - 59)
%n same as \n
%p locale's equivalent of either AM or PM
%r time as %I:%M:%S [AMPM]
%R time as %H:%M
%S seconds (00 - 61), allows for leap seconds
%t insert a tab
%T time as %H:%M:%S
%u weekday as a decimal number (1 - 7), with 1 representing Monday
[XPG4]
%U week number of year (00 - 53), Sunday is the first day of week 1
%V week number of the year (01 - 53), Monday as the first day of the
week. If the week in which the 1st of January falls still has four
or more days to run in the new year, this week is assigned the
number 1. If it does not, then it is given the number 53 for the
preceding year, and the following week is assigned number 1.
[XPG4]
%w week day number (0 - 6), Sunday = 0
%W week number of year (00 - 53), Monday is the first day of week 1
%x locale's appropriate date representation
%X locale's appropriate time representation
Page 2 Reliant UNIX 5.44 Printed 11/98
strftime(3C) strftime(3C)
%y year within century (00 - 99)
%Y year as ccyy (e.g. 1986)
%Z time zone name or noc 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 start-
ing with a Sunday (for %U) or a Monday for (%W). Week number 00 con-
tains those days before the first Sunday or Monday in January for %U
and %W, respectively.
Warning: %f, %V and %u are recognized in XPG4 mode only. %C has a
different effect depending on whether you compiled or are
running the programming in XPG3 mode or in XPG4 mode (the
environment variable determines the mode if the mode is set
dynamically).
If the total number of resulting bytes including the terminating null
byte is not more than maxsize, strftime() returns the number of bytes
placed into the array pointed to by s, not including the terminating
null byte. Otherwise, zero is returned and the contents of the array
are indeterminate. cftime() and ascftime() return the number of bytes
placed into the array pointed to by s not including the terminating
null byte.
Modified Conversion Specifiers
Some conversion specifiers can be modified by the E or O modifier
characters to indicate that an alternative format or specification
should be used rather than the one normally used by the unmodified
conversion specifier (see the "Programmer's Guide: Internationaliza-
tion - Localization"). If the alternative format or specification does
not exist for the current locale, the behavior will be as if the unmo-
dified conversion specification were used.
Warning: These conversion specifiers are recognized in XPG4 mode
only. They are returned without any modifications in XPG3
mode.
%Ec the locale's alternative appropriate date and time representa-
tion
%EC the name of the base year (period) in the locale's alternative
representation
%Ex the locale's alternative date representation
%EX the locale's alternative time representation
%Ey the offset from %EC (year only) in the locale's alternative rep-
resentation
Page 3 Reliant UNIX 5.44 Printed 11/98
strftime(3C) strftime(3C)
%EY the full alternative year representation
%Od the day of the month, using the locale's alternative numeric
symbols, filled as needed with leading zeros if there is any
alternative symbol for zero, otherwise with leading spaces
%Oe the day of month, using the locale's alternative numeric sym-
bols, filled as needed with leading spaces
%OH the hour (24-hour clock) using the locale's alternative numeric
symbols
%OI the hour (12-hour clock) using the locale's alternative numeric
symbols
%Om the month using the locale's alternative numeric symbols
%OM the minutes using the locale's alternative numeric symbols
%OS the seconds using the locale's alternative numeric symbols
%Ou the weekday as a number in the the locale's alternative repre-
sentation (Monday = 1)
%OU the week number of the year (Sunday as the first day of the
week, rules corresponding to %U) using the locale's alternative
numeric symbols
%OV the week number of the year (Monday as the first day of the
week, rule corresponding to %V) using the locale's alternative
numeric symbols
%Ow the number of the weekday (Sunday = 0) using the locale's alter-
native numeric symbols
%OW the week number of the year (Monday as the first day of the
week) using the locale's alternative numeric symbols
%Oy the year (offset from %C) in the locale's alternative represen-
tation and using the locale's alternative symbols
Selecting the output language
By default, the output of strftime(), cftime(), and ascftime() appear
in US English. The user can request that the output of strftime(),
cftime() or ascftime() be in a specific language by using setlocale()
to set the LCTIME category for the locale.
Timezone
The timezone is taken from the environment variable TZ [see
ctime(3C)].
Page 4 Reliant UNIX 5.44 Printed 11/98
strftime(3C) strftime(3C)
EXAMPLES
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 Jersey.
strftime (str, strsize, "%A %b %d %j", tmptr)
This results in str containing "Thursday Aug 28 240".
NOTES
cftime() and ascftime() are obsolete. strftime() should be used
instead.
Please note that some conversion specifiers are recognized in XPG4
mode only. These are returned without any modifications in XPG3 mode.
FILES
/usr/lib/locale/locale/LCTIME
file containing locale specific date and time information
SEE ALSO
ctime(3C), getenv(3C), setlocale(3C), LCTIME(4), timezone(4),
environ(5), time(5).
Page 5 Reliant UNIX 5.44 Printed 11/98