strftime(3)strftime(3)Namestrftime - convert time and date to string
Syntax
#include <time.h>
int strftime (s, maxsize, format, tm)
char *s;
size_t maxsize;
char *format;
struct tm *tm;
Description
The function places characters in the array pointed to by s. No more
than maxsize characters are placed into the array. The string controls
this process. This string consists of zero or more directives and
ordinary characters. A directive consists of a character followed by a
character that determines the behavior of the directive. All ordinary
characters are copied unchanged into the array, including the terminat‐
ing null character.
Each directive is replaced by the appropriate characters as shown in
the following table. The characters are determined by the program's
locale category and the values contained in the structure pointed to by
tm.
─────────────────────────────────────────────────────────────
Directive Replaced by
─────────────────────────────────────────────────────────────
%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 date and time representation
%d Day of month as a decimal number (01-31)
%D Date (%m/%d/%y)
%h Locale's abbreviated month name
%H Hour as a decimal number (00-23)
%I Hour as a decimal number (01-12)
%j Day of year (001-366)
%m Number of month (01-12)
%M Minute number (00-59)
%n Newline character
%p Locale's equivalent to AM or PM
%r Time in AM/PM notation
%S Second number (00-59)
%t Tab character
%T Time (%H/%M/%S)
%U Week number (00-53), Sunday as first day of week
%w Weekday number (0[Sunday]-6)
%W Week number (00-53), Monday as first day of week
%x Locale's date representation
%X Locale's time representation
%y Year without century (00-99)
%Y Year with century
%Z Timezone name, no characters if no timezone
%% %
─────────────────────────────────────────────────────────────
If a directive is used that is not contained in the table, the results
are undefined.
International Environment
LC_TIME Contains the user's requirements for language, terri‐
tory, and codeset for the time format. affects the
behavior of the time functions in If is not defined in
the current environment, provides the necessary default.
LANG If this environment is set and valid, uses the interna‐
tional language database named in the definition to
determine the time formatting rules. If is defined, its
definition supercedes the definition of
Return Values
If the total number of resulting characters, including the terminal
null character, is not more than maxsize, the function returns the
total of resultant characters placed into the array pointed to by s,
not including the terminating null character. In all other cases zero
is returned and the contents of the array are indeterminate.
As the name is not contained in the tm structure the value returned by
%Z is determined by the function, see
See Alsoctime(3), setlocale(3)strftime(3)