#include <time.h>size_t strftime(char *str, size_t maxsize,  const char *fmt,                const struct tm *time);

The strftime( ) function stores time and date information, along with other information, into the string pointed to by str according to the format commands found in the string pointed to by fmt and using the broken-down time pointed to by time. A maximum of maxsize characters will be placed into str.

In C99, str, fmt, and time are qualified by restrict.

The strftime( ) function works a little like sprintf( ) in that it recognizes a set of format commands that begin with the percent sign (%) and it stores its formatted output into a string. The format commands are used to specify the exact way various time and date information is represented in str. Any other characters found in the format string are placed into str unchanged. The time and date displayed are in local time. The format commands are shown in the table below. Notice that many of the commands are case sensitive.

The strftime( ) function returns the number of characters stored in the string pointed to by str or zero if an error occurs.


Replaced By


Abbreviated weekday name


Full weekday name


Abbreviated month name


Full month name


Standard date and time string


Last two digits of year


Day of month as a decimal (1–31)


month/day/year (added by C99)


Day of month as a decimal (1–31) in a 2-character field
(added by C99)


Year-month-day (added by C99)


Last two digits of year using a week-based year (added by C99)


The year using a week-based year (added by C99)


Abbreviated month name (added by C99)


Hour (0–23)


Hour (1–12)


Day of year as a decimal (1–366)


Month as decimal (1–12)


Minute as decimal (0–59)


A newline (added by C99)


Locale’s equivalent of A.M. or P.M.


12-hour time (added by C99)


hh:mm (added by C99)


Second as decimal (0–60)


Horizontal tab (added by C99)


hh:mm:ss (added by C99)


Day of week; Monday is first day of week (1–7) (added by C99)


Week of year, Sunday being first day (0–53)


Week of year using a week-based year (added by C99)


Weekday as a decimal (0–6, Sunday being 0)


Week of year, Monday being first day (0–53)


Standard date string


Standard time string


Year in decimal without century (0–99)


Year including century as decimal


Offset from UTC (added by C99)


Time zone name


The percent sign

C99 allows certain of the strftime( ) format commands to be modified by E or O. The E can modify c, C, x, X, y, Y, d, e, and H. The O can modify I, m, M, S, u, U, V, w, W, and y. These modifiers cause an alternative representation of the time and/or date to be displayed. Consult your compiler’s documentation for details.

A week-based year is used by the %g, %G, and %V format commands. With this representation, Monday is the first day of the week and the first week of a year must include January 4th.

Related functions are time( ), localtime( ), and gmtime( ).

C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net