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.