Initial import from FreeBSD RELENG_4:
[dragonfly.git] / 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: src/lib/libc/stdtime/strftime.3,v 1.18.2.10 2003/05/24 00:01:31 keramida 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).  If the week containing January
188 1 has four or more days in the new year, then it is week 1; otherwise
189 it is the last week of the previous year, and the next week is week 1.
190 .It Cm %v
191 is equivalent to
192 .Dq Li %e-%b-%Y .
193 .It Cm \&%W
194 is replaced by the week number of the year (Monday as the first day of
195 the week) as a decimal number (00-53).
196 .It Cm %w
197 is replaced by the weekday (Sunday as the first day of the week)
198 as a decimal number (0-6).
199 .It Cm \&%X
200 is replaced by national representation of the time.
201 .It Cm %x
202 is replaced by national representation of the date.
203 .It Cm \&%Y
204 is replaced by the year with century as a decimal number.
205 .It Cm %y
206 is replaced by the year without century as a decimal number (00-99).
207 .It Cm \&%Z
208 is replaced by the time zone name.
209 .It Cm \&%z
210 is replaced by the time zone offset from UTC; a leading plus sign stands for
211 east of UTC, a minus sign for west of UTC, hours and minutes follow
212 with two digits each and no delimiter between them (common form for
213 RFC 822 date headers).
214 .It Cm %+
215 is replaced by national representation of the date and time
216 (the format is similar to that produced by
217 .Xr date 1 ) .
218 .It Cm %%
219 is replaced by
220 .Ql % .
221 .El
222 .Sh SEE ALSO
223 .Xr date 1 ,
224 .Xr printf 1 ,
225 .Xr ctime 3 ,
226 .Xr printf 3 ,
227 .Xr strptime 3
228 .Sh STANDARDS
229 The
230 .Fn strftime
231 function
232 conforms to
233 .St -isoC
234 with a lot of extensions including
235 .Ql %C ,
236 .Ql \&%D ,
237 .Ql %E* ,
238 .Ql %e ,
239 .Ql %G ,
240 .Ql %g ,
241 .Ql %h ,
242 .Ql %k ,
243 .Ql %l ,
244 .Ql %n ,
245 .Ql %O* ,
246 .Ql \&%R ,
247 .Ql %r ,
248 .Ql %s ,
249 .Ql \&%T ,
250 .Ql %t ,
251 .Ql %u ,
252 .Ql \&%V ,
253 .Ql %z ,
254 .Ql %+ .
255 .Pp
256 The peculiar week number and year in the replacements of
257 .Ql %G ,
258 .Ql %g
259 and
260 .Ql \&%V
261 are defined in ISO 8601: 1988.
262 .Sh BUGS
263 There is no conversion specification for the phase of the moon.