Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / lib / libc / stdtime / strftime.3
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.2 2003/06/17 04:26:46 dillon 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
58 The
59 .Fn strftime
60 function formats the information from
61 .Fa timeptr
62 into the buffer
63 .Fa buf
64 according to the string pointed to by
65 .Fa format .
66 .Pp
67 The
68 .Fa format
69 string consists of zero or more conversion specifications and
70 ordinary characters.
71 All ordinary characters are copied directly into the buffer.
72 A conversion specification consists of a percent sign
73 .Dq Ql %
74 and one other character.
75 .Pp
76 No more than
77 .Fa maxsize
78 characters will be placed into the array.
79 If the total number of resulting characters, including the terminating
80 NUL character, is not more than
81 .Fa maxsize ,
82 .Fn strftime
83 returns the number of characters in the array, not counting the
84 terminating NUL.
85 Otherwise, zero is returned and the buffer contents are indeterminate.
86 .Pp
87 The conversion specifications are copied to the buffer after expansion
88 as follows:-
89 .Bl -tag -width "xxxx"
90 .It Cm \&%A
91 is replaced by national representation of the full weekday name.
92 .It Cm %a
93 is replaced by national representation of
94 the abbreviated weekday name.
95 .It Cm \&%B
96 is replaced by national representation of the full month name.
97 .It Cm %b
98 is replaced by national representation of
99 the abbreviated month name.
100 .It Cm \&%C
101 is replaced by (year / 100) as decimal number; single
102 digits are preceded by a zero.
103 .It Cm %c
104 is replaced by national representation of time and date.
105 .It Cm \&%D
106 is equivalent to
107 .Dq Li %m/%d/%y .
108 .It Cm %d
109 is replaced by the day of the month as a decimal number (01-31).
110 .It Cm \&%E* Cm \&%O*
111 POSIX locale extensions.
112 The sequences
113 %Ec %EC %Ex %EX %Ey %EY
114 %Od %Oe %OH %OI %Om %OM
115 %OS %Ou %OU %OV %Ow %OW %Oy
116 are supposed to provide alternate
117 representations.
118 .Pp
119 Additionly %OB implemented
120 to represent alternative months names
121 (used standalone, without day mentioned).
122 .It Cm %e
123 is replaced by the day of month as a decimal number (1-31); single
124 digits are preceded by a blank.
125 .It Cm \&%F
126 is equivalent to
127 .Dq Li %Y-%m-%d .
128 .It Cm \&%G
129 is replaced by a year as a decimal number with century.
130 This year is the one that contains the greater part of
131 the week (Monday as the first day of the week).
132 .It Cm %g
133 is replaced by the same year as in
134 .Dq Li %G ,
135 but as a decimal number without century (00-99).
136 .It Cm \&%H
137 is replaced by the hour (24-hour clock) as a decimal number (00-23).
138 .It Cm %h
139 the same as %b.
140 .It Cm \&%I
141 is replaced by the hour (12-hour clock) as a decimal number (01-12).
142 .It Cm %j
143 is replaced by the day of the year as a decimal number (001-366).
144 .It Cm %k
145 is replaced by the hour (24-hour clock) as a decimal number (0-23);
146 single digits are preceded by a blank.
147 .It Cm %l
148 is replaced by the hour (12-hour clock) as a decimal number (1-12);
149 single digits are preceded by a blank.
150 .It Cm \&%M
151 is replaced by the minute as a decimal number (00-59).
152 .It Cm %m
153 is replaced by the month as a decimal number (01-12).
154 .It Cm %n
155 is replaced by a newline.
156 .It Cm \&%O*
157 the same as %E*.
158 .It Cm %p
159 is replaced by national representation of either
160 "ante meridiem"
161 or
162 "post meridiem"
163 as appropriate.
164 .It Cm \&%R
165 is equivalent to
166 .Dq Li %H:%M .
167 .It Cm %r
168 is equivalent to
169 .Dq Li %I:%M:%S %p .
170 .It Cm \&%S
171 is replaced by the second as a decimal number (00-60).
172 .It Cm %s
173 is replaced by the number of seconds since the Epoch, UTC (see
174 .Xr mktime 3 ) .
175 .It Cm \&%T
176 is equivalent to
177 .Dq Li %H:%M:%S .
178 .It Cm %t
179 is replaced by a tab.
180 .It Cm \&%U
181 is replaced by the week number of the year (Sunday as the first day of
182 the week) as a decimal number (00-53).
183 .It Cm %u
184 is replaced by the weekday (Monday as the first day of the week)
185 as a decimal number (1-7).
186 .It Cm \&%V
187 is replaced by the week number of the year (Monday as the first day of
188 the week) as a decimal number (01-53).  If the week containing January
189 1 has four or more days in the new year, then it is week 1; otherwise
190 it is the last week of the previous year, and the next week is week 1.
191 .It Cm %v
192 is equivalent to
193 .Dq Li %e-%b-%Y .
194 .It Cm \&%W
195 is replaced by the week number of the year (Monday as the first day of
196 the week) as a decimal number (00-53).
197 .It Cm %w
198 is replaced by the weekday (Sunday as the first day of the week)
199 as a decimal number (0-6).
200 .It Cm \&%X
201 is replaced by national representation of the time.
202 .It Cm %x
203 is replaced by national representation of the date.
204 .It Cm \&%Y
205 is replaced by the year with century as a decimal number.
206 .It Cm %y
207 is replaced by the year without century as a decimal number (00-99).
208 .It Cm \&%Z
209 is replaced by the time zone name.
210 .It Cm \&%z
211 is replaced by the time zone offset from UTC; a leading plus sign stands for
212 east of UTC, a minus sign for west of UTC, hours and minutes follow
213 with two digits each and no delimiter between them (common form for
214 RFC 822 date headers).
215 .It Cm %+
216 is 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 %%
220 is 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
230 The
231 .Fn strftime
232 function
233 conforms to
234 .St -isoC
235 with 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
257 The peculiar week number and year in the replacements of
258 .Ql %G ,
259 .Ql %g
260 and
261 .Ql \&%V
262 are defined in ISO 8601: 1988.
263 .Sh BUGS
264 There is no conversion specification for the phase of the moon.