strftime
---flexible calendar time formatter#include <time.h> size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timp);Description
strftime
converts a struct tm
representation of the time (at
timp) into a string, starting at s and occupying no more than
maxsize characters.
You control the format of the output using the string at format.
*format
can contain two kinds of specifications: text to be
copied literally into the formatted string, and time conversion
specifications. Time conversion specifications are two-character
sequences beginning with `%
' (use `%%
' to include a percent
sign in the output). Each defined conversion specification selects a
field of calendar time data from *timp
, and converts it to a
string in one of the following ways:
%a
%A
%b
%B
%c
Mon Apr 01 13:13:13 1992
%d
%H
%I
%j
001
' to `366
').
%m
%M
%p
AM
' or `PM
' as appropriate.
%S
%U
00
' to `53
';
week number 1 is taken as beginning with the first Sunday in a year).
See also %W
.
%w
0
.
%W
%U
', but counting week 1
as beginning with the first Monday in a year.
o %x
Mon Apr 01 1992
%X
13:13:13
%y
%Y
%Z
%Z
' but generates
no output for it).
%%
%
'.
Returns
When the formatted time takes up no more than maxsize characters,
the result is the length of the formatted string. Otherwise, if the
formatting operation was abandoned due to lack of room, the result is
0
, and the string starting at s corresponds to just those
parts of *format
that could be completely filled in within the
maxsize limit.
Portability
ANSI C requires strftime
, but does not specify the contents of
*s
when the formatted string would require more than
maxsize characters.
strftime
requires no supporting OS subroutines.