xref: /freebsd/lib/libc/stdtime/strftime.3 (revision 3e0f6b97b257a96f7275e4442204263e44b16686)
1.\" Copyright (c) 1989, 1991, 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" the American National Standards Committee X3, on Information
6.\" Processing Systems.
7.\"
8.\" Redistribution and use in source and binary forms, with or without
9.\" modification, are permitted provided that the following conditions
10.\" are met:
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\"    notice, this list of conditions and the following disclaimer in the
15.\"    documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software
17.\"    must display the following acknowledgement:
18.\"	This product includes software developed by the University of
19.\"	California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\"    may be used to endorse or promote products derived from this software
22.\"    without specific prior written permission.
23.\"
24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE.
35.\"
36.\"     @(#)strftime.3	8.1 (Berkeley) 6/4/93
37.\"
38.Dd June 4, 1993
39.Dt STRFTIME 3
40.Os
41.Sh NAME
42.Nm strftime
43.Nd format date and time
44.Sh SYNOPSIS
45.Fd #include <time.h>
46.Ft size_t
47.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
48.Sh DESCRIPTION
49The
50.Fn strftime
51function formats the information from
52.Fa timeptr
53into the buffer
54.Fa buf
55according to the string pointed to by
56.Fa format .
57.Pp
58The
59.Fa format
60string consists of zero or more conversion specifications and
61ordinary characters.
62All ordinary characters are copied directly into the buffer.
63A conversion specification consists of a percent sign
64.Dq Ql %
65and one other character.
66.Pp
67No more than
68.Fa maxsize
69characters will be placed into the array.
70If the total number of resulting characters, including the terminating
71null character, is not more than
72.Fa maxsize ,
73.Fn strftime
74returns the number of characters in the array, not counting the
75terminating null.
76Otherwise, zero is returned.
77.Pp
78Each conversion specification is replaced by the characters as
79follows which are then copied into the buffer.
80.Bl -tag -width "xxxx"
81.It Cm \&%A
82is replaced by national representation of the full weekday name.
83.It Cm %a
84is replaced by national representation of
85the abbreviated weekday name, where the abbreviation
86is the first three characters.
87.It Cm \&%B
88is replaced by national representation of the full month name.
89.It Cm %b
90is replaced by national representation of
91the abbreviated month name, where the abbreviation is
92the first three characters.
93.It Cm \&%C
94is replaced by (year / 100) as decimal number; single
95digits are preceded by a zero.
96.It Cm %c
97is replaced by national representation of time and date
98(the format is similar with produced by
99.Xr asctime 3 ) .
100.It Cm \&%D
101is equivalent to
102.Dq Li %m/%d/%y .
103.It Cm %d
104is replaced by the day of the month as a decimal number (01-31).
105.It Cm \&%E*
106POSIX locale extensions.
107The sequences
108%Ec %EC %Ex %Ey %EY
109%Od %Oe %OH %OI %Om %OM
110%OS %Ou %OU %OV %Ow %OW %Oy
111are supposed to provide alternate
112representations.
113.It Cm %e
114is replaced by the day of month as a decimal number (1-31); single
115digits are preceded by a blank.
116.It Cm \&%H
117is replaced by the hour (24-hour clock) as a decimal number (00-23).
118.It Cm %h
119the same as %b.
120.It Cm \&%I
121is replaced by the hour (12-hour clock) as a decimal number (01-12).
122.It Cm %j
123is replaced by the day of the year as a decimal number (001-366).
124.It Cm %k
125is replaced by the hour (24-hour clock) as a decimal number (0-23);
126single digits are preceded by a blank.
127.It Cm %l
128is replaced by the hour (12-hour clock) as a decimal number (1-12);
129single digits are preceded by a blank.
130.It Cm \&%M
131is replaced by the minute as a decimal number (00-59).
132.It Cm %m
133is replaced by the month as a decimal number (01-12).
134.It Cm %n
135is replaced by a newline.
136.It Cm \&%O*
137the same as %E*.
138.It Cm %p
139is replaced by national representation of either
140"ante meridiem"
141or
142"post meridiem"
143as appropriate.
144.It Cm \&%R
145is equivalent to
146.Dq Li %H:%M .
147.It Cm %r
148is equivalent to
149.Dq Li %I:%M:%S %p .
150.It Cm \&%S
151is replaced by the second as a decimal number (00-60).
152.It Cm %s
153is replaced by the number of seconds since the Epoch, UTC (see
154.Xr mktime 3 ) .
155.It Cm \&%T
156is equivalent to
157.Dq Li %H:%M:%S .
158.It Cm %t
159is replaced by a tab.
160.It Cm \&%U
161is replaced by the week number of the year (Sunday as the first day of
162the week) as a decimal number (00-53).
163.It Cm %u
164is replaced by the weekday (Monday as the first day of the week)
165as a decimal number (1-7).
166.It Cm \&%V
167is replaced by the week number of the year (the first
168Monday as the first day of week 1) as a
169decimal number (01-53).
170.It Cm %v
171is equivalent to
172.Dq Li %e-%b-%Y .
173.It Cm \&%W
174is replaced by the week number of the year (Monday as the first day of
175the week) as a decimal number (00-53).
176.It Cm %w
177is replaced by the weekday (Sunday as the first day of the week)
178as a decimal number (0-6).
179.It Cm \&%X
180is replaced by national representation of the time.
181.It Cm %x
182is replaced by national representation of the date.
183.It Cm \&%Y
184is replaced by the year with century as a decimal number.
185.It Cm %y
186is replaced by the year without century as a decimal number (00-99).
187.It Cm \&%Z
188is replaced by the time zone name.
189.It Cm %+
190is replaced by national representation of the date and time
191(the format is similar with produced by
192.Xr date 1 ) .
193.It Cm %%
194is replaced by
195.Ql % .
196.El
197.Sh SEE ALSO
198.Xr date 1 ,
199.Xr printf 1 ,
200.Xr ctime 3 ,
201.Xr printf 3
202.Sh STANDARDS
203The
204.Fn strftime
205function
206conforms to
207.St -ansiC .
208The
209.Ql %s
210conversion specification is an extension.
211.Sh BUGS
212There is no conversion specification for the phase of the moon.
213