Scroll Down to See All
abortabsacosasctimeasctime_rasinassertatanatan2atexitatofatoiatolbsearchbtowccalloccatclosecatgetscatopenceilclearerrclockcoscoshctimectime_rdifftimediverferfcexitexpfabsfclosefdopenfeofferrorfflushfgetcfgetposfgetsfgetwcfgetwsfopenfprintffputcfputwsfreadfreefreopenfrexpfscanffseekfsetposftellfwidefwprintffwritefwscanfgetcgetchargetenvgetwcgetwchargmtimegmtime_rhypotisalnumisalphaisasciiisblankiscntrlisdigitisgraphislowerisprintispunctisspaceisupperiswalnumiswalphaiswblankiswcntrliswctypeiswdigitiswgraphiswloweriswprintiswpunctiswspaceiswupperiswxdigitisxdigitj0j1jnlabsldexpldivlocaleconvlocaltimelocaltime_rloglog10longjmpmallocmblenmbrlenmbrtowcmbsinitmbsrtowcsmbstowcsmbtowcmemchrmemcmpmemcpymemmovememsetmktimemodfnextafternextafterlnexttowardnexttowardlnl_langinfoperrorpowprintfputcputcharputenvputsputwcputwcharqsortquantexpd32quantexpd64quantexpd128quantized32quantized64quantized128samequantumd32raiserandrand_rreallocregcompregerrorregexecregfreeremoverenamerewindscanfsetbufsetjmpsetlocalesetvbufsignalsinsinhsnprintfsprintfsqrtsrandsscanfstrcasecmpstrcatstrchrstrcmpstrcollstrcpystrcspnstrerrorstrfmonstrlenstrncasecmpstrncatstrncmpstrncpystrpbrkstrptimestrrchrstrspnstrstrstrtodstrtod32strtod64strtod128strtofstrtokstrtok_rstrtolstrtoldstrtoulstrxfrmswprintfswscanfsystemtantanhtimetime64tmpfiletmpnamtoasciitolowertouppertowctranstowlowertowupperungetcungetwcva_argva_copyva_endva_startvfprintfvfscanfvfwprintfvfwscanfvprintfvscanfvsprintfvsnprintfvsscanfvswprintfvswscanfvwprintfvwscanfwcrtombwcscatwcschrwcscmpwcscollwcscpywcscpywcsftimewcslenwcsncatwcsncmpwcsncpywcspbrkwcsptimewcsrchrwcsrtombswcsspnwcsstrwcstodwcstod32wcstod64wcstod128wcstofwcstokwcstolwcstoldwcstombswcstoulwcsxfrmwctobwctombwctranswctypewcwidthwmemchrwmemcmpwmemcpywmemmovewmemsetwprintfwscanfy0y1yn



Function Details : strftime

size_tstrftime(char * str,size_t maxsize,const char * format,const struct tm * timeptr) ;

Return Type : size_t

Platform-specific unsigned type for array indices and memory sizes.
Read about return values of strftime function .

1st Parameter Type : char *

String pointer (array of characters)

1st Parameter

Pointer to the buffer where the formatted date and time string will be stored.

2nd Parameter Type : size_t

Platform-specific unsigned type for array indices and memory sizes.

2nd Parameter

The maximum number of bytes, including the null terminator, that can be written to the buffer.

3rd Parameter Type : const char *

Pointer to read-only string

3rd Parameter

A null-terminated format string specifying how to format the date and time, using specifiers like `%Y`, `%m`, or `%d`.

4th Parameter Type : const struct tm *

Pointer to a constant `struct tm`, which represents broken-down time values including year, month, day, hour, minute, and second.

4th Parameter

Pointer to a `struct tm` containing the broken-down time values to be formatted.

Read more about parameters of strftime in parameters section
The strftimefunction in C language Formats the time and date according to the locale settings and format string.
The strftime function formats the time represented in the struct tm object according to the formatting rules defined in format. The resulting C string is stored in the character array pointed by str.
The strftimefunction takes 4 parameters:
  • char * `str`: Pointer to the buffer where the formatted date and time string will be stored.
  • size_t `maxsize`: The maximum number of bytes, including the null terminator, that can be written to the buffer.
  • const char * `format`: A null-terminated format string specifying how to format the date and time, using specifiers like `%Y`, `%m`, or `%d`.
  • const struct tm * `timeptr`: Pointer to a `struct tm` containing the broken-down time values to be formatted.
Formats the time specified by `timeptr` according to the format string `format` and writes the result to the buffer `str`. Writes at most `maxsize` bytes, including the null terminator. Returns the number of bytes written (excluding the null terminator), or `0` if the formatted string would exceed `maxsize`.
The strftime function return value :
  • Returns the number of characters placed in the array str if the total number including the terminating null character is not more than max
  • Otherwise, it returns 0 and the contents of the array are indeterminate

Output

This example demonstrates basic usage of strftime to format the current date and time.