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), strftime() leaves s unchanged and the function returns unsuccessfully. The format string determines the conversion process. This string contains text, which is copied one-to-one to s, and format specifiers. Format specifiers always start with % sign and are replaced by the following:

Table 1. strftime() Output String Content and Format
Format Replaced With
%a Abbreviated name of the weekday of the current locale (for example, Fri)
%A Full name of the weekday of the current locale (for example, Friday)
%b Abbreviated name of the month of the current locale (for example, Feb)
%B Full name of the month of the current locale (for example, 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 (for example, 93)
%Y The year, including the century (for example, 1993)
%Z The time zone, if it can be determined.
%% A single % sign
Return

Returns zero if the resulting string has more than max characters; otherwise returns the length of the created string.

See also

mktime()

setlocale()

time()