xref: /freebsd/lib/libc/stdtime/strftime.3 (revision 33b77e2decd50e53798014b70bf7ca3bdc4c0c7e)
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 October 4, 1997
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 and the buffer contents is indeterminate.
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 \&%G
117is replaced by a year as a decimal number with century.
118This year is the one that contains the greater part of
119the week (Monday as the first day of the week).
120.It Cm %g
121is replaced by the same year as in
122.Dq Li %G ,
123but as a decimal number without century (00-99).
124.It Cm \&%H
125is replaced by the hour (24-hour clock) as a decimal number (00-23).
126.It Cm %h
127the same as %b.
128.It Cm \&%I
129is replaced by the hour (12-hour clock) as a decimal number (01-12).
130.It Cm %j
131is replaced by the day of the year as a decimal number (001-366).
132.It Cm %k
133is replaced by the hour (24-hour clock) as a decimal number (0-23);
134single digits are preceded by a blank.
135.It Cm %l
136is replaced by the hour (12-hour clock) as a decimal number (1-12);
137single digits are preceded by a blank.
138.It Cm \&%M
139is replaced by the minute as a decimal number (00-59).
140.It Cm %m
141is replaced by the month as a decimal number (01-12).
142.It Cm %n
143is replaced by a newline.
144.It Cm \&%O*
145the same as %E*.
146.It Cm %p
147is replaced by national representation of either
148"ante meridiem"
149or
150"post meridiem"
151as appropriate.
152.It Cm \&%R
153is equivalent to
154.Dq Li %H:%M .
155.It Cm %r
156is equivalent to
157.Dq Li %I:%M:%S %p .
158.It Cm \&%S
159is replaced by the second as a decimal number (00-60).
160.It Cm %s
161is replaced by the number of seconds since the Epoch, UTC (see
162.Xr mktime 3 ) .
163.It Cm \&%T
164is equivalent to
165.Dq Li %H:%M:%S .
166.It Cm %t
167is replaced by a tab.
168.It Cm \&%U
169is replaced by the week number of the year (Sunday as the first day of
170the week) as a decimal number (00-53).
171.It Cm %u
172is replaced by the weekday (Monday as the first day of the week)
173as a decimal number (1-7).
174.It Cm \&%V
175is replaced by the week number of the year (Monday as the first day of
176the week) as a decimal number (01-53).  If the week containing January
1771 has four or more days in the new year, then it is week 1; otherwise
178it is the last week of the previous year, and the next week is week 1.
179.It Cm %v
180is equivalent to
181.Dq Li %e-%b-%Y .
182.It Cm \&%W
183is replaced by the week number of the year (Monday as the first day of
184the week) as a decimal number (00-53).
185.It Cm %w
186is replaced by the weekday (Sunday as the first day of the week)
187as a decimal number (0-6).
188.It Cm \&%X
189is replaced by national representation of the time.
190.It Cm %x
191is replaced by national representation of the date.
192.It Cm \&%Y
193is replaced by the year with century as a decimal number.
194.It Cm %y
195is replaced by the year without century as a decimal number (00-99).
196.It Cm \&%Z
197is replaced by the time zone name.
198.It Cm %+
199is replaced by national representation of the date and time
200(the format is similar with produced by
201.Xr date 1 ) .
202.It Cm %%
203is replaced by
204.Ql % .
205.El
206.Sh SEE ALSO
207.Xr date 1 ,
208.Xr printf 1 ,
209.Xr ctime 3 ,
210.Xr printf 3 ,
211.Xr strptime 3
212.Sh STANDARDS
213The
214.Fn strftime
215function
216conforms to
217.St -ansiC
218with a lot of extensions including
219.Ql %C ,
220.Ql %D ,
221.Ql %E* ,
222.Ql %e ,
223.Ql %G ,
224.Ql %g ,
225.Ql %h ,
226.Ql %k ,
227.Ql %l ,
228.Ql %n ,
229.Ql %O* ,
230.Ql \&%R ,
231.Ql %r ,
232.Ql %s ,
233.Ql \&%T ,
234.Ql %t ,
235.Ql %u ,
236.Ql \&%V ,
237.Ql %+ .
238
239The peculiar week number and year in the replacements of
240.Ql %G ,
241.Ql %g
242and
243.Ql \&%V
244are defined in ISO 8601: 1988.
245
246.Sh BUGS
247There is no conversion specification for the phase of the moon.
248