]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/lib/libc/stdtime/strftime.3
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / 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$
38 .\"
39 .Dd November 4, 2004
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 .In time.h
49 .Ft size_t
50 .Fo strftime
51 .Fa "char * restrict buf"
52 .Fa "size_t maxsize"
53 .Fa "const char * restrict format"
54 .Fa "const struct tm * restrict timeptr"
55 .Fc
56 .Sh DESCRIPTION
57 The
58 .Fn strftime
59 function formats the information from
60 .Fa timeptr
61 into the buffer
62 .Fa buf
63 according to the string pointed to by
64 .Fa format .
65 .Pp
66 The
67 .Fa format
68 string consists of zero or more conversion specifications and
69 ordinary characters.
70 All ordinary characters are copied directly into the buffer.
71 A conversion specification consists of a percent sign
72 .Dq Ql %
73 and one other character.
74 .Pp
75 No more than
76 .Fa maxsize
77 characters will be placed into the array.
78 If the total number of resulting characters, including the terminating
79 NUL character, is not more than
80 .Fa maxsize ,
81 .Fn strftime
82 returns the number of characters in the array, not counting the
83 terminating NUL.
84 Otherwise, zero is returned and the buffer contents are indeterminate.
85 .Pp
86 The conversion specifications are copied to the buffer after expansion
87 as follows:-
88 .Bl -tag -width "xxxx"
89 .It Cm \&%A
90 is replaced by national representation of the full weekday name.
91 .It Cm %a
92 is replaced by national representation of
93 the abbreviated weekday name.
94 .It Cm \&%B
95 is replaced by national representation of the full month name.
96 .It Cm %b
97 is replaced by national representation of
98 the abbreviated month name.
99 .It Cm \&%C
100 is replaced by (year / 100) as decimal number; single
101 digits are preceded by a zero.
102 .It Cm %c
103 is replaced by national representation of time and date.
104 .It Cm \&%D
105 is equivalent to
106 .Dq Li %m/%d/%y .
107 .It Cm %d
108 is replaced by the day of the month as a decimal number (01-31).
109 .It Cm %E* %O*
110 POSIX locale extensions.
111 The sequences
112 %Ec %EC %Ex %EX %Ey %EY
113 %Od %Oe %OH %OI %Om %OM
114 %OS %Ou %OU %OV %Ow %OW %Oy
115 are supposed to provide alternate
116 representations.
117 .Pp
118 Additionally %OB implemented
119 to represent alternative months names
120 (used standalone, without day mentioned).
121 .It Cm %e
122 is replaced by the day of month as a decimal number (1-31); single
123 digits are preceded by a blank.
124 .It Cm \&%F
125 is equivalent to
126 .Dq Li %Y-%m-%d .
127 .It Cm \&%G
128 is replaced by a year as a decimal number with century.
129 This year is the one that contains the greater part of
130 the week (Monday as the first day of the week).
131 .It Cm %g
132 is replaced by the same year as in
133 .Dq Li %G ,
134 but as a decimal number without century (00-99).
135 .It Cm \&%H
136 is replaced by the hour (24-hour clock) as a decimal number (00-23).
137 .It Cm %h
138 the same as
139 .Cm %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
158 .Cm %E* .
159 .It Cm %p
160 is replaced by national representation of either
161 "ante meridiem"
162 or
163 "post meridiem"
164 as appropriate.
165 .It Cm \&%R
166 is equivalent to
167 .Dq Li %H:%M .
168 .It Cm %r
169 is equivalent to
170 .Dq Li %I:%M:%S %p .
171 .It Cm \&%S
172 is replaced by the second as a decimal number (00-60).
173 .It Cm %s
174 is replaced by the number of seconds since the Epoch, UTC (see
175 .Xr mktime 3 ) .
176 .It Cm \&%T
177 is equivalent to
178 .Dq Li %H:%M:%S .
179 .It Cm %t
180 is replaced by a tab.
181 .It Cm \&%U
182 is replaced by the week number of the year (Sunday as the first day of
183 the week) as a decimal number (00-53).
184 .It Cm %u
185 is replaced by the weekday (Monday as the first day of the week)
186 as a decimal number (1-7).
187 .It Cm \&%V
188 is replaced by the week number of the year (Monday as the first day of
189 the week) as a decimal number (01-53).
190 If the week containing January
191 1 has four or more days in the new year, then it is week 1; otherwise
192 it is the last week of the previous year, and the next week is week 1.
193 .It Cm %v
194 is equivalent to
195 .Dq Li %e-%b-%Y .
196 .It Cm \&%W
197 is replaced by the week number of the year (Monday as the first day of
198 the week) as a decimal number (00-53).
199 .It Cm %w
200 is replaced by the weekday (Sunday as the first day of the week)
201 as a decimal number (0-6).
202 .It Cm \&%X
203 is replaced by national representation of the time.
204 .It Cm %x
205 is replaced by national representation of the date.
206 .It Cm \&%Y
207 is replaced by the year with century as a decimal number.
208 .It Cm %y
209 is replaced by the year without century as a decimal number (00-99).
210 .It Cm \&%Z
211 is replaced by the time zone name.
212 .It Cm %z
213 is replaced by the time zone offset from UTC; a leading plus sign stands for
214 east of UTC, a minus sign for west of UTC, hours and minutes follow
215 with two digits each and no delimiter between them (common form for
216 RFC 822 date headers).
217 .It Cm %+
218 is 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 %-*
222 GNU libc extension.
223 Do not do any padding when performing numerical outputs.
224 .It Cm %_*
225 GNU libc extension.
226 Explicitly specify space for padding.
227 .It Cm %0*
228 GNU libc extension.
229 Explicitly specify zero for padding.
230 .It Cm %%
231 is replaced by
232 .Ql % .
233 .El
234 .Sh SEE ALSO
235 .Xr date 1 ,
236 .Xr printf 1 ,
237 .Xr ctime 3 ,
238 .Xr printf 3 ,
239 .Xr strptime 3 ,
240 .Xr wcsftime 3
241 .Sh STANDARDS
242 The
243 .Fn strftime
244 function
245 conforms to
246 .St -isoC
247 with a lot of extensions including
248 .Ql %C ,
249 .Ql \&%D ,
250 .Ql %E* ,
251 .Ql %e ,
252 .Ql %G ,
253 .Ql %g ,
254 .Ql %h ,
255 .Ql %k ,
256 .Ql %l ,
257 .Ql %n ,
258 .Ql %O* ,
259 .Ql \&%R ,
260 .Ql %r ,
261 .Ql %s ,
262 .Ql \&%T ,
263 .Ql %t ,
264 .Ql %u ,
265 .Ql \&%V ,
266 .Ql %z ,
267 .Ql %+ .
268 .Pp
269 The peculiar week number and year in the replacements of
270 .Ql %G ,
271 .Ql %g
272 and
273 .Ql \&%V
274 are defined in ISO 8601: 1988.
275 .Sh BUGS
276 There is no conversion specification for the phase of the moon.
277 .Pp
278 The
279 .Fn strftime
280 function does not correctly handle multibyte characters in the
281 .Fa format
282 argument.