Home >>C Time Library Function >C strftime() function

C strftime() function

C strftime() function

C time strtime() function is used to format the time represented in the structure timeptr according to the formatting rules defined in format and stored into str. It takes 4 arguments: str, count, format and time.

Syntax:
size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)

Parameter Values

Parameter Description
str: It is pointer to the first element of the character array to store the result.
count: It is the maximum number of bytes to write.
format: It is the pointer to a null-terminated multibyte character string specifying the format of conversion.
Here is an example of strtime() function:

#include <stdio.h>
#include <time.h>
int main () 
{
time_t rawtime;
struct tm *info;
char buffer[80];
time( &rawtime );
info = localtime( &rawtime );
strftime(buffer,80,"%x - %I:%M%p", info);
printf("Formatted date & time : |%s|\n", buffer );
return(0);
}

Output:
Formatted date & time : |04/15/20 - 11:37AM|

No Sidebar ads