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