English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The functionstrftime()
used to format time and date into a string. Declared in the C language 'time.h' header file. It returns the total number of characters copied to the string, or zero if the string size is less than the character count.
This isstrftime()
C language syntax,
size_t strftime(char *string, size_t size, const char *format, const struct tm *time_pointer)
Here,
String-A pointer to the target array.
Size-The maximum number of characters to copy.
Format-Some special format specifiers, represented by tm, to indicate time.
time_pointer-a pointer to the tm structure that contains calendar time.
This isstrftime()
C language example,
#include <stdio.h> #include <time.h> int main () { time_t tim; struct tm *detl; char buf[80]; time(&tim); detl = localtime(&tim); strftime(buf, 20, "%x - "%I:%M%p", detl); printf("Date & time after formatting: %s", buf); return(0); }
Output result
Date & time after formatting : 10/23/18 - 10:33AM
In the above program, three variables of different data types are declared. This featurelocaltime()
The function is storing the current date and time.strftime()
Copy the string and format it into a special structure using some special notations.
detl = localtime(&tim); strftime(buf, 20, "%x - "%I:%M%p", detl);