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