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