.TH strftime() "" "" "Time Function (libc)"
.PC "Format locale-specific time"
.B "#include <time.h>"
\fBsize_t strftime(\fIstring\^\fB, \fImaximum\^\fB, \fIformat\^\fB, \fB\fIbrokentime\^\fB)
\fBchar *\fIstring\^\fB; size_t \fImaximum\^\fB; const char *\fIformat\^\fB;\fR
	\fBconst struct tm *\fIbrokentime\^\fB;
.PP
.II "time^format locale specific"
The function
.B strftime()
provides a locale-specific way to print the current time and date.
It also gives you an easy way to shuffle the elements of date and time into
a string that suits your preferences.
.PP
.B strftime()
references the portion of the locale that is affected by the calls
.DM
	setlocale(LC_TIME, \fIlocale\fP);
.DE
.PP
or
.DM
	setlocale(LC_ALL, \fIlocale\fL);
.DE
.PP
For more information on setting locales, see the entry for
.BR localization .
.PP
.I string
points to the region of memory into which
.B strftime()
writes the date and time string it generates.
.I maximum
is the maximum number of characters that can be written into
.IR string .
.I string
should point to an area of allocated memory at least
.IR maximum +1
bytes long; if it does not, reserved portions of memory may be overwritten.
.PP
.I brokentime
points to a structure of type
.BR tm ,
which contains the broken-down time.
This structure must first be initialized by either of the functions
.B localtime()
or
.BR gmtime() .
.PP
Finally,
.I format
points to a string that contains one or more conversion specifications,
which guide
.B strftime()
in building its output string.
Each conversion specification is introduced by the percent sign \*(Ql%\*(Qr.
When the output string is built, each conversion specification
is replaced by the appropriate time element.
Characters within
.I format
that are not part of a conversion specification are copied into
.IR string ;
to write a literal percent sign, use \*(QL%%\*(QR.
.PP
.B strftime()
recognizes the following conversion specifiers:
.IP \fBa\fR 0.3i
The locale's abbreviated name for the day of the week.
.IS \fBA\fR
The locale's full name for the day of the week.
.IS \fBb\fR
The locale's abbreviated name for the month.
.IS \fBB\fR
The locale's full name for the month.
.IS \fBc\fR
The locale's default representation for the date and time.
.IS \fBd\fR
The day of the month as an integer (01 through 31).
.IS \fBH\fR
The hour as an integer (00 through 23).
.IS \fBI\fR
The hour as an integer (01 through 12).
.IS \fBj\fR
The day of the year as an integer (001 through 366).
.IS \fBm\fR
The month as an integer (01 through 12).
.IS \fBM\fR
The minute as an integer (00 through 59).
.IS \fBp\fR
The locale's way of indicating morning or afternoon
(e.g, in the United States, \*(QLAM\*(QR or \*(QLPM\*(QR).
.IS \fBS\fR
The second as an integer (00 through 59).
.IS \fBU\fR
The week of the year as an integer (00 through 53);
regard Sunday as the first day of the week.
.IS \fBw\fR
The day of the week as an integer (0 through 6);
regard Sunday as the first day of the week.
.IS \fBW\fR
The day of the week as an integer (0 through 6);
regard Monday as the first day of the week.
.IS \fBx\fR
The locale's default representation of the date.
.IS \fBX\fR
The locale's default representation of the time.
.IS \fBy\fR
The year within the century (00 through 99).
.IS \fBY\fR
The full year, including century.
.IS \fBz\fR
The name of the locale's time zone.
If no time zone can be determined, print a null string.
.PP
Use of any conversion specifier other than the ones listed above will
result in undefined behavior.
.PP
If the number of characters written into
.I string
is less than or equal to
.IR maximum ,
then
.B strftime()
returns the number of characters written.
If, however, the number of characters to be written exceeds
.IR maximum ,
then
.B strftime()
returns zero and the contents of the area pointed to by
.I string
are indeterminate.
.SH "See Also"
.Xr "asctime()," asctime
.Xr "ctime()," ctime
.Xr "gmtime()," gmtime
.Xr "libc," libc
.Xr "localtime()," localtime
.Xr "time [overview]" time.a
.br
\*(AS, \(sc7.12.3.5
.br
\*(PX Standard, \(sc8.1
