Customizing Date and Time Formats with strftime(3)

The string format of the date and time can vary considerably with the preference of each user. The strftime(3) function makes it easier for the C programmer to implement custom date and time formats. Its synopsis is as follows:

#include <time.h>

size_t strftime(char *buf, size_t maxsize,
    const char *format, const struct tm *timeptr);

The arguments buf and maxsize specify the receiving buffer and its maximum size, respectively. The argument format specifies a printf(3)-like format string. The last argument, timeptr, points to a struct tm structure that will supply all of the input date and time values. The final output string size is returned, excluding the null byte.

If the output buffer is ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.