strftime
Formats time for output.
Defined in header <time.h>
Syntax
#include <time.h>
size_t strftime(char *s,size_t maxsize, const char *fmt,conststruct tm *t);
Portability
| DOS | UNIX | Windows | ANSI C | C++ only |
|---|---|---|---|---|
| ■ | ■ | ■ |
Remarks
strftime formats the time in the argument t into the array pointed to by the argument s according to the fmt specifications. The format string consists of zero or more directives and ordinary characters. Like printf, a directive consists of the % character followed by a character that determines the substitution that is to take place. All ordinary characters are copied unchanged. No more than maxsize characters are placed in s.
Return value
strftime returns the number of characters placed into s. If the number of characters required is greater than maxsize, strftime returns 0.
Format specifier Substitutes
| %% | Character % |
| %a | Abbreviated weekday name |
| %A | Full weekday name |
| %b | Abbreviated month name |
| %B | Full month name |
| %c | Date and time |
| %d | Two-digit day of the month (01 to 31) |
| %H | Two-digit hour (00 to 23) |
| %I | Two-digit hour (01 to 12) |
| %j | Three-digit day of the year (001 to 366) |
| %m | Two-digit month as a decimal number (1 - 12) |
| %M | Two-digit minute (00 to 59) |
| %p | AM or PM |
| %S | Two-digit second (00 to 59) |
| %u | Two-digit week number where Sunday is the first day of the week (00 to 53) |
| %w | Weekday where 0 is Sunday (0 to 6) |
| %W | Two-digit week number where Monday is the first day of the week (GO to 53) |
| %x | Date |
| %X | Time |
| %y | Two-digit year without century (00 to 99) |
| %Y | Year with century |
| %Z | Time zone name, or no characters if no time zone |
See also
Example
#include <stdio.h>
#include <time.h>
#include <dos.h>
int main(void)
{
struct tm *tirae_now;
time_t secs_now;
char st.r[80] ;
tzset 0;
time(&secs__now) ;
time_now = localtime(&secs_now) ;
strftime (str, 80, "It is %M minutes after 11 o'clock *d 19%y"
time now) ;
printf ("%s\n",str);
return 0;
Differences from modern implementations
Nothing recorded yet.
Modern references
These are search links, not yet checked by hand.
Extraction notes
- heading `strftirme` read as `strftime`
Stable link: /3.1/time.h/strftime/
· short form /3.1/strftime/