strftime()

Syntax
  #include <time.h>

  
  size_t strftime(char *s,

  
                  size_t max,

  
                  const char *format,

  
                  const struct tm *time);

  
Description

strftime() converts time to a character string s. If the conversion results in a string longer than max characters (including the terminating '\0'), s is left unchanged and the function returns unsuccessfully. How the conversion is done is determined by the format string. This string contains text, which is copied one-to-one to s, and format specifiers. The latter always start with a % sign and are replaced by the following, as listed in the table below:

Table 1. strftime() output string content and format
Format Replaced with
%a Abbreviated name of the weekday of the current locale, e.g., Fri.
%A Full name of the weekday of the current locale, e.g., Friday.
%b Abbreviated name of the month of the current locale, e.g., Feb.
%B Full name of the month of the current locale, e.g., February.
%c Date and time in the form given by the current locale.
%d Day of the month in the range from 0 to 31.
%H Hour, in 24-hour-clock format.
%I Hour, in 12-hour-clock format.
%j Day of the year, in the range from 0 to 366.
%m Month, as a decimal number from 0 to 12.
%M Minutes
%p AM/PM specification of a 12-hour clock or equivalent of current locale.
%S Seconds
%U Week number in the range from 0 to 53, with Sunday as the first day of the first week.
%w Day of the week (Sunday = 0, Saturday = 6).
%W Week number in the range from 0 to 53, with Monday as the first day of the first week.
%x The date in format given by current locale.
%X The time in format given by current locale.
%y The year in short format, e.g., "93".
%Y The year, including the century (e.g., "2007").
%Z The time zone, if it can be determined.
%% A single '%' sign.
Return

If the resulting string would have had more than max characters, zero is returned; otherwise the length of the created string is returned.

See also

mktime(),

setlocale(), and

time()