by Dinesh Thakur Category: Function and Pointer

The syntax of the function is as follows:

size_t strftime(char* s, size_t maxsize, const char* format, const struct tm * Tmptr);

The function strftime () formats the broken-down time tm into an array pointed to by s according to the specified formatting string pointed to by format. The size of array is limited by maxsize. The formatting string consists of 0 or more conversion Specifiers and ordinary characters. The ordinary characters placed in the formatting string are copied into s without any conversion. Each specifier consists of a percent character(%) followed by a character that determines the action of conversion specifier. Some conversion Specifiers may have an additional modifier character E or 0 placed between% symbol and the conversion specifier character. The strftime() function returns the number of characters placed in the arrays, not including the terminating Null character.

Illustrates application of function strftime ().

#include <stdio.h>

#include <time.h>
void main()
  time_t Justnow;
  struct tm *Date;
  char string[15];
  time(& Justnow);
  Date= localtime(& Justnow);
  strftime(string, sizeof (string), "%d-%b-%y\n", Date);
  printf("%s", string);

Function strftime () in C

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles