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