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 );
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 formatdata type has been updated to reflect the previous and current documentation, that is, const wchar_t *.
This function validates its parameters. If strDest, format, ortimeptr 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.
_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:
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.