Strftime Function

  • It is used for formatting time and date into a string .
  • It works a little as sprintf() .
  • It returns the number of characters stored in the string pointed to by the pointer (str) or zero if an error occurs.
  • The printing alphabet after "%" may contain any alphabet . You may try out different combinations below .

  • Syntax:

     size_t strftime(char *str, size_t maxsize, const char *fmt, const struct tm *time)


    #include <time.h>
      #include <stdio.h>
      int main()
        struct tm *xyz;
        time_t l;
        char str[90];
        l = time(NULL);
        xyz = localtime(&l);
        strftime(str, 100, "It is now %I %p.", xyz);
        return 0;