strftime, wcsftime, _strftime_l, _wcsftime_l
Format a time string.
size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr ); size_t _strftime_l( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr, _locale_t locale ); size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr ); size_t _wcsftime_l( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr, _locale_t locale );
Size of the strDest buffer, measured in characters (char or wchart_t).
tm data structure.
The locale to use.
strftime returns the number of characters placed in strDest and wcsftime returns the corresponding number of wide characters.
If the total number of characters, including the terminating null, is more than maxsize, both strftime and wcsftime return 0 and the contents of strDest are indeterminate.
The number of characters in strDest is equal to the number of literal characters in format as well as any characters that may be added to format via formatting codes. The terminating null of a string is not counted in the return value.
The strftime and wcsftime functions format the tm time value in timeptr according to the supplied format argument and store the result in the buffer strDest. At most, maxsize characters are placed in the string. For a description of the fields in the timeptr structure, see asctime. wcsftime is the wide-character equivalent of strftime; its string-pointer argument points to a wide-character string. These functions behave identically otherwise.
In versions before Visual C++ 2005, the documentation described the format parameter of wcsftime as having the data type const wchar_t *, but the actual implementation of the format data type was const char *. The implementation of the format data type has been updated to reflect the previous and current documentation, that is, const wchar_t *.
This function validates its parameters. If strDest, format, or timeptr is a null pointer, or if the tm data structure addressed by timeptr is invalid (for example, if it contains out of range values for the time or date), or if the format string contains an invalid formatting code, the invalid parameter handler is invoked, as described in Parameter Validation. If execution is allowed to continue, the function returns 0 and sets errno to EINVAL.
Generic-Text Routine Mappings
_UNICODE & _MBCS not defined
The format argument consists of one or more codes; as in printf, the formatting codes are preceded by a percent sign (%). Characters that do not begin with % are copied unchanged to strDest. The LC_TIME category of the current locale affects the output formatting of strftime. (For more information on LC_TIME, see setlocale.) The functions without the _l suffix use the currently set locale. The versions of these functions with the _l suffix are identical except that they take the locale as a parameter and use that instead of the currently set locale. For more information, see Locale.
The formatting codes for strftime are listed below:
Abbreviated weekday name
Full weekday name
Abbreviated month name
Full month name
Date and time representation appropriate for locale
Day of month as decimal number (01 – 31)
Hour in 24-hour format (00 – 23)
Hour in 12-hour format (01 – 12)
Day of year as decimal number (001 – 366)
Month as decimal number (01 – 12)
Minute as decimal number (00 – 59)
Current locale's A.M./P.M. indicator for 12-hour clock
Second as decimal number (00 – 59)
Week of year as decimal number, with Sunday as first day of week (00 – 53)
Weekday as decimal number (0 – 6; Sunday is 0)
Week of year as decimal number, with Monday as first day of week (00 – 53)
Date representation for current locale
Time representation for current locale
Year without century, as decimal number (00 – 99)
Year with century, as decimal number
- %z, %Z
Either the time-zone name or time zone abbreviation, depending on registry settings; no characters if time zone is unknown
As in the printf function, the # flag may prefix any formatting code. In that case, the meaning of the format code is changed as follows.
%#a, %#A, %#b, %#B, %#p, %#X, %#z, %#Z, %#%
# flag is ignored.
Long date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".
Long date representation, appropriate to current locale. For example: "Tuesday, March 14, 1995".
%#d, %#H, %#I, %#j, %#m, %#M, %#S, %#U, %#w, %#W, %#y, %#Y
Remove leading zeros (if any).
<time.h> or <wchar.h>
<time.h> or <wchar.h>
For additional compatibility information, see Compatibility in the Introduction.
See the example for time.