xref: /freebsd/lib/libc/stdtime/strftime.3 (revision 23f282aa31e9b6fceacd449020e936e98d6f2298)
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.\" $FreeBSD$
38.\"
39.Dd October 4, 1997
40.Dt STRFTIME 3
41.Os
42.Sh NAME
43.Nm strftime
44.Nd format date and time
45.Sh LIBRARY
46.Lb libc
47.Sh SYNOPSIS
48.Fd #include <time.h>
49.Ft size_t
50.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
51.Sh DESCRIPTION
52The
53.Fn strftime
54function formats the information from
55.Fa timeptr
56into the buffer
57.Fa buf
58according to the string pointed to by
59.Fa format .
60.Pp
61The
62.Fa format
63string consists of zero or more conversion specifications and
64ordinary characters.
65All ordinary characters are copied directly into the buffer.
66A conversion specification consists of a percent sign
67.Dq Ql %
68and one other character.
69.Pp
70No more than
71.Fa maxsize
72characters will be placed into the array.
73If the total number of resulting characters, including the terminating
74NUL character, is not more than
75.Fa maxsize ,
76.Fn strftime
77returns the number of characters in the array, not counting the
78terminating NUL.
79Otherwise, zero is returned and the buffer contents is indeterminate.
80.Pp
81The conversion specifications are copied to the buffer after expansion
82as follows:-
83.Bl -tag -width "xxxx"
84.It Cm \&%A
85is replaced by national representation of the full weekday name.
86.It Cm %a
87is replaced by national representation of
88the abbreviated weekday name, where the abbreviation
89is the first three characters.
90.It Cm \&%B
91is replaced by national representation of the full month name.
92.It Cm %b
93is replaced by national representation of
94the abbreviated month name, where the abbreviation is
95the first three characters.
96.It Cm \&%C
97is replaced by (year / 100) as decimal number; single
98digits are preceded by a zero.
99.It Cm %c
100is replaced by national representation of time and date
101(the format is similar with produced by
102.Xr asctime 3 ) .
103.It Cm \&%D
104is equivalent to
105.Dq Li %m/%d/%y .
106.It Cm %d
107is replaced by the day of the month as a decimal number (01-31).
108.It Cm \&%E* Cm \&%O*
109POSIX locale extensions.
110The sequences
111%Ec %EC %Ex %EX %Ey %EY
112%Od %Oe %OH %OI %Om %OM
113%OS %Ou %OU %OV %Ow %OW %Oy
114are supposed to provide alternate
115representations.
116.Pp
117Additionly %Ef implemented to represent short month name / day
118order of the date, %EF to represent long month name / day
119order
120and %OB to represent alternative months names
121(used standalone, without day mentioned).
122.It Cm %e
123is replaced by the day of month as a decimal number (1-31); single
124digits are preceded by a blank.
125.It Cm \&%G
126is replaced by a year as a decimal number with century.
127This year is the one that contains the greater part of
128the week (Monday as the first day of the week).
129.It Cm %g
130is replaced by the same year as in
131.Dq Li %G ,
132but as a decimal number without century (00-99).
133.It Cm \&%H
134is replaced by the hour (24-hour clock) as a decimal number (00-23).
135.It Cm %h
136the same as %b.
137.It Cm \&%I
138is replaced by the hour (12-hour clock) as a decimal number (01-12).
139.It Cm %j
140is replaced by the day of the year as a decimal number (001-366).
141.It Cm %k
142is replaced by the hour (24-hour clock) as a decimal number (0-23);
143single digits are preceded by a blank.
144.It Cm %l
145is replaced by the hour (12-hour clock) as a decimal number (1-12);
146single digits are preceded by a blank.
147.It Cm \&%M
148is replaced by the minute as a decimal number (00-59).
149.It Cm %m
150is replaced by the month as a decimal number (01-12).
151.It Cm %n
152is replaced by a newline.
153.It Cm \&%O*
154the same as %E*.
155.It Cm %p
156is replaced by national representation of either
157"ante meridiem"
158or
159"post meridiem"
160as appropriate.
161.It Cm \&%R
162is equivalent to
163.Dq Li %H:%M .
164.It Cm %r
165is equivalent to
166.Dq Li %I:%M:%S %p .
167.It Cm \&%S
168is replaced by the second as a decimal number (00-60).
169.It Cm %s
170is replaced by the number of seconds since the Epoch, UTC (see
171.Xr mktime 3 ) .
172.It Cm \&%T
173is equivalent to
174.Dq Li %H:%M:%S .
175.It Cm %t
176is replaced by a tab.
177.It Cm \&%U
178is replaced by the week number of the year (Sunday as the first day of
179the week) as a decimal number (00-53).
180.It Cm %u
181is replaced by the weekday (Monday as the first day of the week)
182as a decimal number (1-7).
183.It Cm \&%V
184is replaced by the week number of the year (Monday as the first day of
185the week) as a decimal number (01-53).  If the week containing January
1861 has four or more days in the new year, then it is week 1; otherwise
187it is the last week of the previous year, and the next week is week 1.
188.It Cm %v
189is equivalent to
190.Dq Li %e-%b-%Y .
191.It Cm \&%W
192is replaced by the week number of the year (Monday as the first day of
193the week) as a decimal number (00-53).
194.It Cm %w
195is replaced by the weekday (Sunday as the first day of the week)
196as a decimal number (0-6).
197.It Cm \&%X
198is replaced by national representation of the time.
199.It Cm %x
200is replaced by national representation of the date.
201.It Cm \&%Y
202is replaced by the year with century as a decimal number.
203.It Cm %y
204is replaced by the year without century as a decimal number (00-99).
205.It Cm \&%Z
206is replaced by the time zone name.
207.It Cm \&%z
208is replaced by the time zone offset from UTC; a leading plus sign stands for
209east of UTC, a minus sign for west of UTC, hours and minutes follow
210with two digits each and no delimiter between them (common form for
211RFC 822 date headers).
212.It Cm %+
213is replaced by national representation of the date and time
214(the format is similar to that produced by
215.Xr date 1 ) .
216.It Cm %%
217is replaced by
218.Ql % .
219.El
220.Sh SEE ALSO
221.Xr date 1 ,
222.Xr printf 1 ,
223.Xr ctime 3 ,
224.Xr printf 3 ,
225.Xr strptime 3
226.Sh STANDARDS
227The
228.Fn strftime
229function
230conforms to
231.St -ansiC
232with a lot of extensions including
233.Ql %C ,
234.Ql %D ,
235.Ql %E* ,
236.Ql %e ,
237.Ql %G ,
238.Ql %g ,
239.Ql %h ,
240.Ql %k ,
241.Ql %l ,
242.Ql %n ,
243.Ql %O* ,
244.Ql \&%R ,
245.Ql %r ,
246.Ql %s ,
247.Ql \&%T ,
248.Ql %t ,
249.Ql %u ,
250.Ql \&%V ,
251.Ql %z ,
252.Ql %+ .
253
254The peculiar week number and year in the replacements of
255.Ql %G ,
256.Ql %g
257and
258.Ql \&%V
259are defined in ISO 8601: 1988.
260
261.Sh BUGS
262There is no conversion specification for the phase of the moon.
263