O'Reilly logo

Advanced UNIX Programming by Warren W. Gay

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required