strftime

Description

Formats a time string.

#include <time.h> Required only for function declarations  

size_t strftime( char *string, size_t maxsize, const char *format,
const struct tm *timeptr );

string Output string  
maxsize Maximum length of string  
format Format control string  
timeptr tm data structure  

Remarks

The strftime function formats the tm time value in timeptr according to the supplied format argument and stores the result in the buffer string. At most, maxsize characters are placed in the string.

The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a % sign. Characters that do not begin with a % sign are copied unchanged to string. The LC_TIME category of the current locale affects the output formatting of strftime.

The formatting codes for strftime are listed below:

Format Description

%a Abbreviated weekday name
%A Full weekday name
%b Abbreviated month name
%B Full month name
%c Date and time representation appropriate for the locale
%d Day of the month as a decimal number (01 – 31)
%H Hour in 24-hour format (00 – 23)
%I Hour in 12-hour format (01 – 12)
%j Day of the year as a decimal number (001 – 366)
%m Month as a decimal number (01 – 12)
%M Minute as a decimal number (00 – 59)
%p Current locale's AM/PM indicator for a 12-hour clock
%S Second as a decimal number (00 – 59)
%U Week of the year as a decimal number; with Sunday as the first day of the week (00 – 51)
%w Weekday as a decimal number (0 – 6; Sunday is 0)
%W Week of the year as a decimal number; with Monday as the first day of the week (00 – 51)
%x Date representation for current locale
%X Time representation for current locale
%y Year without the century as a decimal number (00 – 99)
%Y Year with the century as a decimal number
%z Time zone name or abbreviation; no characters if time zone is unknown
%% Percent sign

Return Value

The strftime function returns the number of characters placed in string if the total number of resulting characters, including the terminating null, is not more than maxsize.

Otherwise, strftime returns 0, and the contents of the string are indeterminate.

Compatibility

Standards:ANSI

16-Bit:DOS, QWIN, WIN

32-Bit:DOS32X

See Also

localeconv, setlocale, strcoll, strxfrm

Example

See the example for time.