xref: /freebsd/lib/libc/stdtime/strftime.3 (revision df7f5d4de4592a8948a25ce01e5bddfbb7ce39dc)
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.\"
38.Dd June 4, 1993
39.Dt STRFTIME 3
40.Os
41.Sh NAME
42.Nm strftime
43.Nd format date and time
44.Sh SYNOPSIS
45.Fd #include <time.h>
46.Ft size_t
47.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
48.Sh DESCRIPTION
49The
50.Fn strftime
51function formats the information from
52.Fa timeptr
53into the buffer
54.Fa buf
55according to the string pointed to by
56.Fa format .
57.Pp
58The
59.Fa format
60string consists of zero or more conversion specifications and
61ordinary characters.
62All ordinary characters are copied directly into the buffer.
63A conversion specification consists of a percent sign
64.Dq Ql %
65and one other character.
66.Pp
67No more than
68.Fa maxsize
69characters will be placed into the array.  If more characters than
70.Fa maxsize
71could have been written into
72.Fa buf
73then
74.Fa bug
75will not be
76.Sq Li \&\e0
77terminated.
78If the total number of resulting characters, including the terminating
79.Sq Li \&\e0
80character, is not more than
81.Fa maxsize ,
82.Fn strftime
83returns the number of characters in the array, not counting the
84terminating
85.Sq Li \&\e0 .
86Otherwise, zero is returned.
87.Pp
88Each conversion specification is replaced by the characters as
89follows which are then copied into the buffer.
90.Bl -tag -width "xxxx"
91.It Cm \&%A
92is replaced by national representation of the full weekday name.
93.It Cm %a
94is replaced by national representation of
95the abbreviated weekday name, where the abbreviation
96is the first three characters.
97.It Cm \&%B
98is replaced by national representation of the full month name.
99.It Cm %b
100is replaced by national representation of
101the abbreviated month name, where the abbreviation is
102the first three characters.
103.It Cm \&%C
104is replaced by (year / 100) as decimal number; single
105digits are preceded by a zero.
106.It Cm %c
107is replaced by national representation of time and date
108(the format is similar with produced by
109.Xr asctime 3 ) .
110.It Cm \&%D
111is equivalent to
112.Dq Li %m/%d/%y .
113.It Cm %d
114is replaced by the day of the month as a decimal number (01-31).
115.It Cm \&%E*
116POSIX locale extensions.
117The sequences
118%Ec %EC %Ex %Ey %EY
119%Od %Oe %OH %OI %Om %OM
120%OS %Ou %OU %OV %Ow %OW %Oy
121are supposed to provide alternate
122representations.
123.It Cm %e
124is replaced by the day of month as a decimal number (1-31); single
125digits are preceded by a blank.
126.It Cm \&%H
127is replaced by the hour (24-hour clock) as a decimal number (00-23).
128.It Cm %h
129the same as %b.
130.It Cm \&%I
131is replaced by the hour (12-hour clock) as a decimal number (01-12).
132.It Cm %j
133is replaced by the day of the year as a decimal number (001-366).
134.It Cm %k
135is replaced by the hour (24-hour clock) as a decimal number (0-23);
136single digits are preceded by a blank.
137.It Cm %l
138is replaced by the hour (12-hour clock) as a decimal number (1-12);
139single digits are preceded by a blank.
140.It Cm \&%M
141is replaced by the minute as a decimal number (00-59).
142.It Cm %m
143is replaced by the month as a decimal number (01-12).
144.It Cm %n
145is replaced by a newline.
146.It Cm \&%O*
147the same as %E*.
148.It Cm %p
149is replaced by national representation of either
150"ante meridiem"
151or
152"post meridiem"
153as appropriate.
154.It Cm \&%R
155is equivalent to
156.Dq Li %H:%M .
157.It Cm %r
158is equivalent to
159.Dq Li %I:%M:%S %p .
160.It Cm \&%S
161is replaced by the second as a decimal number (00-60).
162.It Cm %s
163is replaced by the number of seconds since the Epoch, UTC (see
164.Xr mktime 3 ) .
165.It Cm \&%T
166is equivalent to
167.Dq Li %H:%M:%S .
168.It Cm %t
169is replaced by a tab.
170.It Cm \&%U
171is replaced by the week number of the year (Sunday as the first day of
172the week) as a decimal number (00-53).
173.It Cm %u
174is replaced by the weekday (Monday as the first day of the week)
175as a decimal number (1-7).
176.It Cm \&%V
177is replaced by the week number of the year (the first
178Monday as the first day of week 1) as a
179decimal number (01-53).
180.It Cm %v
181is equivalent to
182.Dq Li %e-%b-%Y .
183.It Cm \&%W
184is replaced by the week number of the year (Monday as the first day of
185the week) as a decimal number (00-53).
186.It Cm %w
187is replaced by the weekday (Sunday as the first day of the week)
188as a decimal number (0-6).
189.It Cm \&%X
190is replaced by national representation of the time.
191.It Cm %x
192is replaced by national representation of the date.
193.It Cm \&%Y
194is replaced by the year with century as a decimal number.
195.It Cm %y
196is replaced by the year without century as a decimal number (00-99).
197.It Cm \&%Z
198is replaced by the time zone name.
199.It Cm %+
200is replaced by national representation of the date and time
201(the format is similar with produced by
202.Xr date 1 ) .
203.It Cm %%
204is replaced by
205.Ql % .
206.El
207.Sh SEE ALSO
208.Xr date 1 ,
209.Xr printf 1 ,
210.Xr ctime 3 ,
211.Xr printf 3
212.Sh STANDARDS
213The
214.Fn strftime
215function
216conforms to
217.St -ansiC .
218The
219.Ql %s
220conversion specification is an extension.
221.Sh BUGS
222There is no conversion specification for the phase of the moon.
223