]> git.saurik.com Git - apple/libc.git/blame - stdtime/FreeBSD/strftime.3
Libc-1439.100.3.tar.gz
[apple/libc.git] / stdtime / FreeBSD / strftime.3
CommitLineData
5b2abdfb
A
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.
5b2abdfb
A
16.\" 4. Neither the name of the University nor the names of its contributors
17.\" may be used to endorse or promote products derived from this software
18.\" without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93
1f2f436a 33.\" $FreeBSD: src/lib/libc/stdtime/strftime.3,v 1.40 2008/05/16 04:33:04 grog Exp $
5b2abdfb 34.\"
1f2f436a 35.Dd November 4, 2004
5b2abdfb
A
36.Dt STRFTIME 3
37.Os
38.Sh NAME
ad3c9f2a
A
39.Nm strftime ,
40.Nm strftime_l
5b2abdfb
A
41.Nd format date and time
42.Sh LIBRARY
43.Lb libc
44.Sh SYNOPSIS
45.In time.h
46.Ft size_t
9385eb3d 47.Fo strftime
ad3c9f2a 48.Fa "char *restrict s"
9385eb3d 49.Fa "size_t maxsize"
ad3c9f2a
A
50.Fa "const char *restrict format"
51.Fa "const struct tm *restrict timeptr"
52.Fc
53.In time.h
54.In xlocale.h
55.Ft size_t
56.Fo strftime_l
57.Fa "char *restrict s"
58.Fa "size_t maxsize"
59.Fa "const char *restrict format"
60.Fa "const struct tm *restrict timeptr"
61.Fa "locale_t loc"
9385eb3d 62.Fc
5b2abdfb
A
63.Sh DESCRIPTION
64The
65.Fn strftime
66function formats the information from
67.Fa timeptr
68into the buffer
ad3c9f2a 69.Fa s ,
5b2abdfb
A
70according to the string pointed to by
71.Fa format .
72.Pp
73The
74.Fa format
75string consists of zero or more conversion specifications and
76ordinary characters.
77All ordinary characters are copied directly into the buffer.
78A conversion specification consists of a percent sign
79.Dq Ql %
80and one other character.
81.Pp
82No more than
83.Fa maxsize
84characters will be placed into the array.
85If the total number of resulting characters, including the terminating
86NUL character, is not more than
87.Fa maxsize ,
88.Fn strftime
89returns the number of characters in the array, not counting the
90terminating NUL.
9385eb3d 91Otherwise, zero is returned and the buffer contents are indeterminate.
5b2abdfb 92.Pp
ad3c9f2a
A
93Although the
94.Fn strftime
95function uses the current locale, the
96.Fn strftime_l
97function may be passed a locale directly. See
98.Xr xlocale 3
99for more information.
100.Pp
5b2abdfb
A
101The conversion specifications are copied to the buffer after expansion
102as follows:-
103.Bl -tag -width "xxxx"
104.It Cm \&%A
105is replaced by national representation of the full weekday name.
106.It Cm %a
107is replaced by national representation of
9385eb3d 108the abbreviated weekday name.
5b2abdfb
A
109.It Cm \&%B
110is replaced by national representation of the full month name.
111.It Cm %b
112is replaced by national representation of
9385eb3d 113the abbreviated month name.
5b2abdfb
A
114.It Cm \&%C
115is replaced by (year / 100) as decimal number; single
116digits are preceded by a zero.
117.It Cm %c
118is replaced by national representation of time and date.
5b2abdfb
A
119.It Cm \&%D
120is equivalent to
121.Dq Li %m/%d/%y .
122.It Cm %d
123is replaced by the day of the month as a decimal number (01-31).
1f2f436a 124.It Cm %E* %O*
5b2abdfb
A
125POSIX locale extensions.
126The sequences
127%Ec %EC %Ex %EX %Ey %EY
128%Od %Oe %OH %OI %Om %OM
129%OS %Ou %OU %OV %Ow %OW %Oy
130are supposed to provide alternate
131representations.
132.Pp
1f2f436a 133Additionally %OB implemented
9385eb3d 134to represent alternative months names
5b2abdfb
A
135(used standalone, without day mentioned).
136.It Cm %e
1f2f436a 137is replaced by the day of the month as a decimal number (1-31); single
5b2abdfb 138digits are preceded by a blank.
9385eb3d
A
139.It Cm \&%F
140is equivalent to
141.Dq Li %Y-%m-%d .
5b2abdfb
A
142.It Cm \&%G
143is replaced by a year as a decimal number with century.
144This year is the one that contains the greater part of
145the week (Monday as the first day of the week).
146.It Cm %g
147is replaced by the same year as in
148.Dq Li %G ,
149but as a decimal number without century (00-99).
150.It Cm \&%H
151is replaced by the hour (24-hour clock) as a decimal number (00-23).
152.It Cm %h
1f2f436a
A
153the same as
154.Cm %b .
5b2abdfb
A
155.It Cm \&%I
156is replaced by the hour (12-hour clock) as a decimal number (01-12).
157.It Cm %j
158is replaced by the day of the year as a decimal number (001-366).
159.It Cm %k
160is replaced by the hour (24-hour clock) as a decimal number (0-23);
161single digits are preceded by a blank.
162.It Cm %l
163is replaced by the hour (12-hour clock) as a decimal number (1-12);
164single digits are preceded by a blank.
165.It Cm \&%M
166is replaced by the minute as a decimal number (00-59).
167.It Cm %m
168is replaced by the month as a decimal number (01-12).
169.It Cm %n
170is replaced by a newline.
1f2f436a
A
171.It Cm %O*
172the same as
173.Cm %E* .
5b2abdfb
A
174.It Cm %p
175is replaced by national representation of either
1f2f436a 176"ante meridiem" (a.m.)
5b2abdfb 177or
1f2f436a 178"post meridiem" (p.m.)
5b2abdfb
A
179as appropriate.
180.It Cm \&%R
181is equivalent to
182.Dq Li %H:%M .
183.It Cm %r
184is equivalent to
185.Dq Li %I:%M:%S %p .
186.It Cm \&%S
187is replaced by the second as a decimal number (00-60).
188.It Cm %s
189is replaced by the number of seconds since the Epoch, UTC (see
190.Xr mktime 3 ) .
191.It Cm \&%T
192is equivalent to
193.Dq Li %H:%M:%S .
194.It Cm %t
195is replaced by a tab.
196.It Cm \&%U
197is replaced by the week number of the year (Sunday as the first day of
198the week) as a decimal number (00-53).
199.It Cm %u
200is replaced by the weekday (Monday as the first day of the week)
201as a decimal number (1-7).
202.It Cm \&%V
203is replaced by the week number of the year (Monday as the first day of
3d9156a7
A
204the week) as a decimal number (01-53).
205If the week containing January
5b2abdfb
A
2061 has four or more days in the new year, then it is week 1; otherwise
207it is the last week of the previous year, and the next week is week 1.
208.It Cm %v
209is equivalent to
210.Dq Li %e-%b-%Y .
211.It Cm \&%W
212is replaced by the week number of the year (Monday as the first day of
213the week) as a decimal number (00-53).
214.It Cm %w
215is replaced by the weekday (Sunday as the first day of the week)
216as a decimal number (0-6).
217.It Cm \&%X
218is replaced by national representation of the time.
219.It Cm %x
220is replaced by national representation of the date.
221.It Cm \&%Y
222is replaced by the year with century as a decimal number.
223.It Cm %y
224is replaced by the year without century as a decimal number (00-99).
225.It Cm \&%Z
226is replaced by the time zone name.
1f2f436a 227.It Cm %z
5b2abdfb
A
228is replaced by the time zone offset from UTC; a leading plus sign stands for
229east of UTC, a minus sign for west of UTC, hours and minutes follow
230with two digits each and no delimiter between them (common form for
231RFC 822 date headers).
232.It Cm %+
233is replaced by national representation of the date and time
234(the format is similar to that produced by
235.Xr date 1 ) .
1f2f436a
A
236.It Cm %-*
237GNU libc extension.
238Do not do any padding when performing numerical outputs.
239.It Cm %_*
240GNU libc extension.
241Explicitly specify space for padding.
242.It Cm %0*
243GNU libc extension.
244Explicitly specify zero for padding.
5b2abdfb
A
245.It Cm %%
246is replaced by
247.Ql % .
248.El
249.Sh SEE ALSO
250.Xr date 1 ,
251.Xr printf 1 ,
252.Xr ctime 3 ,
253.Xr printf 3 ,
9385eb3d 254.Xr strptime 3 ,
ad3c9f2a
A
255.Xr wcsftime 3 ,
256.Xr xlocale 3
5b2abdfb
A
257.Sh STANDARDS
258The
259.Fn strftime
260function
261conforms to
262.St -isoC
263with a lot of extensions including
264.Ql %C ,
265.Ql \&%D ,
266.Ql %E* ,
267.Ql %e ,
268.Ql %G ,
269.Ql %g ,
270.Ql %h ,
271.Ql %k ,
272.Ql %l ,
273.Ql %n ,
274.Ql %O* ,
275.Ql \&%R ,
276.Ql %r ,
277.Ql %s ,
278.Ql \&%T ,
279.Ql %t ,
280.Ql %u ,
281.Ql \&%V ,
282.Ql %z ,
ad3c9f2a 283and
5b2abdfb
A
284.Ql %+ .
285.Pp
286The peculiar week number and year in the replacements of
287.Ql %G ,
ad3c9f2a 288.Ql %g ,
5b2abdfb
A
289and
290.Ql \&%V
291are defined in ISO 8601: 1988.
292.Sh BUGS
293There is no conversion specification for the phase of the moon.
9385eb3d
A
294.Pp
295The
296.Fn strftime
297function does not correctly handle multibyte characters in the
298.Fa format
299argument.