Name
strftime
Synopsis
Generates a formatted time and date string
#include <time.h> size_tstrftime
( char * restricts
, size_tn
, const char * restrictformat
, const struct tm * restricttimeptr
);
The strftime()
function
converts date and time information from a struct tm
object addressed by the last
pointer argument into a character string, following a format
specified by the string addressed by the pointer argument
format
. The strftime()
function stores the resulting
string in the buffer addressed by the first pointer argument,
without exceeding the buffer length specified by the second
argument, n
. The locations that strftime()
reads from and writes to using
its restricted pointer parameters must not overlap.
Typically, the struct tm
object is obtained by calling localtime()
or gmtime()
. For a description of this
structure type, see mktime()
in this
chapter.
The generation of the output string is governed by the format
string. In this way, strftime()
is similar to the functions in the printf()
family. The format string
consists of ordinary characters, which are copied to the output
buffer unchanged, and conversion specifications, which direct
strftime()
to convert a data item
from the struct tm
object and
include it in the output string.
Conversion specification syntax
The conversion specifications have the following syntax:
%[modifier
]specifier
The modifier, if present, instructs strftime()
to use an alternative,
locale-specific conversion for the specified data item, and is
either
Get C in a Nutshell 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.