Format a time string.
size_t strftime( char *strDest, size_t maxsize, const char *format, const struct tm *timeptr ); size_t wcsftime( wchar_t *strDest, size_t maxsize, const wchar_t *format, const struct tm *timeptr );
- Output string.
- Maximum length of string.
- Format-control string.
- tm data structure.
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 is 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.
Note Before this version of Visual C++, the documentation described the format parameter of wcsftime as having the datatype const wchar_t *, but the actual implementation of the format datatype was const char *. In this version, the implementation of the format datatype has been updated to reflect the previous and current documentation, that is: const wchar_t *.
Generic-Text Routine Mappings
|TCHAR.H routine||_UNICODE & _MBCS not defined||_MBCS defined||_UNICODE 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 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
- Percent sign
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.|
|%#c||Long date and time representation, appropriate for current locale. For example: "Tuesday, March 14, 1995, 12:41:29".|
|%#x||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).|
|strftime||<time.h>||ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP|
|wcsftime||<time.h> or <wchar.h>||ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP|
For additional compatibility information, see Compatibility in the Introduction.
All versions of the C run-time libraries.
See the example for time.