strftime

C++ Reference

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

The function strftime() formats date and time information from time to a format specified by fmt, then stores the result in str (up to maxsize characters). Certain codes may be used in fmt to specify different types of time:

Code Meaning
%a abbreviated weekday name (e.g. Fri)
%A full weekday name (e.g. Friday)
%b abbreviated month name (e.g. Oct)
%B full month name (e.g. October)
%c the standard date and time string
%d day of the month, as a number (1-31)
%H hour, 24 hour format (0-23)
%I hour, 12 hour format (1-12)
%j day of the year, as a number (1-366)
%m month as a number (1-12). Note: some versions of Microsoft Visual C++ may use values that range from 0-11.
%M minute as a number (0-59)
%p locale's equivalent of AM or PM
%S second as a number (0-59)
%U week of the year, (0-53), where week 1 has the first Sunday
%w weekday as a decimal (0-6), where Sunday is 0
%W week of the year, (0-53), where week 1 has the first Monday
%x standard date string
%X standard time string
%y year in decimal, without the century (0-99)
%Y year in decimal, with the century
%Z time zone name
%% a percent sign

The strftime() function returns the number of characters put into str, or zero if an error occurs.

Related topics: