]> git.saurik.com Git - apple/libc.git/blob - stdtime/FreeBSD/strftime.3
Libc-583.tar.gz
[apple/libc.git] / stdtime / FreeBSD / 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.34 2004/07/02 23:52:12 ru Exp $
38 .\"
39 .Dd January 4, 2003
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* Cm \&%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 Additionly %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 %b.
139 .It Cm \&%I
140 is replaced by the hour (12-hour clock) as a decimal number (01-12).
141 .It Cm %j
142 is replaced by the day of the year as a decimal number (001-366).
143 .It Cm %k
144 is replaced by the hour (24-hour clock) as a decimal number (0-23);
145 single digits are preceded by a blank.
146 .It Cm %l
147 is replaced by the hour (12-hour clock) as a decimal number (1-12);
148 single digits are preceded by a blank.
149 .It Cm \&%M
150 is replaced by the minute as a decimal number (00-59).
151 .It Cm %m
152 is replaced by the month as a decimal number (01-12).
153 .It Cm %n
154 is replaced by a newline.
155 .It Cm \&%O*
156 the same as %E*.
157 .It Cm %p
158 is replaced by national representation of either
159 "ante meridiem"
160 or
161 "post meridiem"
162 as appropriate.
163 .It Cm \&%R
164 is equivalent to
165 .Dq Li %H:%M .
166 .It Cm %r
167 is equivalent to
168 .Dq Li %I:%M:%S %p .
169 .It Cm \&%S
170 is replaced by the second as a decimal number (00-60).
171 .It Cm %s
172 is replaced by the number of seconds since the Epoch, UTC (see
173 .Xr mktime 3 ) .
174 .It Cm \&%T
175 is equivalent to
176 .Dq Li %H:%M:%S .
177 .It Cm %t
178 is replaced by a tab.
179 .It Cm \&%U
180 is replaced by the week number of the year (Sunday as the first day of
181 the week) as a decimal number (00-53).
182 .It Cm %u
183 is replaced by the weekday (Monday as the first day of the week)
184 as a decimal number (1-7).
185 .It Cm \&%V
186 is replaced by the week number of the year (Monday as the first day of
187 the week) as a decimal number (01-53).
188 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 .Xr wcsftime 3
230 .Sh STANDARDS
231 The
232 .Fn strftime
233 function
234 conforms to
235 .St -isoC
236 with a lot of extensions including
237 .Ql %C ,
238 .Ql \&%D ,
239 .Ql %E* ,
240 .Ql %e ,
241 .Ql %G ,
242 .Ql %g ,
243 .Ql %h ,
244 .Ql %k ,
245 .Ql %l ,
246 .Ql %n ,
247 .Ql %O* ,
248 .Ql \&%R ,
249 .Ql %r ,
250 .Ql %s ,
251 .Ql \&%T ,
252 .Ql %t ,
253 .Ql %u ,
254 .Ql \&%V ,
255 .Ql %z ,
256 .Ql %+ .
257 .Pp
258 The peculiar week number and year in the replacements of
259 .Ql %G ,
260 .Ql %g
261 and
262 .Ql \&%V
263 are defined in ISO 8601: 1988.
264 .Sh BUGS
265 There is no conversion specification for the phase of the moon.
266 .Pp
267 The
268 .Fn strftime
269 function does not correctly handle multibyte characters in the
270 .Fa format
271 argument.