xref: /netbsd-src/lib/libc/time/strftime.3 (revision dc306354b0b29af51801a7632f1e95265a68cd81)
1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
2.\" 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.\"     from: @(#)strftime.3	5.12 (Berkeley) 6/29/91
37.\"	$NetBSD: strftime.3,v 1.5 1998/02/11 18:52:25 kleink Exp $
38.\"
39.Dd June 29, 1991
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.Fd #include <time.h>
49.Ft size_t
50.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
51.Sh DESCRIPTION
52The
53.Fn strftime
54function formats the information from
55.Fa timeptr
56into the buffer
57.Fa buf
58according to the string pointed to by
59.Fa format .
60.Pp
61The
62.Fa format
63string consists of zero or more conversion specifications and
64ordinary characters.
65All ordinary characters are copied directly into the buffer.
66A conversion specification consists of a percent sign
67.Ql %
68and one other character.
69.Pp
70No more than
71.Fa maxsize
72characters will be placed into the array.
73If the total number of resulting characters, including the terminating
74null character, is not more than
75.Fa maxsize ,
76.Fn strftime
77returns the number of characters in the array, not counting the
78terminating null.
79Otherwise, zero is returned.
80.Pp
81Each conversion specification is replaced by the characters as
82follows which are then copied into the buffer.
83.Bl -tag -width "xxxx"
84.It Cm \&%A
85is replaced by the locale's full weekday name.
86.It Cm %a
87is replaced by the locale's abbreviated weekday name.
88.It Cm \&%B
89is replaced by the locale's full month name.
90.It Cm \&%b No or Cm \&%h
91is replaced by the locale's abbreviated month name.
92.It Cm \&%C
93is replaced by the century (a year divided by 100 and truncated to an integer)
94as a decimal number [00,99].
95.It Cm \&%c
96is replaced by the locale's appropriate date and time representation.
97.It Cm \&%D
98is replaced by the date in the format
99.Dq Li %m/%d/%y .
100.It Cm \&%d
101is replaced by the day of the month as a decimal number [01,31].
102.It Cm \&%e
103is replaced by the day of month as a decimal number [1,31];
104single digits are preceded by a blank.
105.It Cm \&%H
106is replaced by the hour (24-hour clock) as a decimal number [00,23].
107.It Cm \&%I
108is replaced by the hour (12-hour clock) as a decimal number [01,12].
109.It Cm \&%j
110is replaced by the day of the year as a decimal number [001,366].
111.It Cm \&%k
112is replaced by the hour (24-hour clock) as a decimal number [0,23];
113single digits are preceded by a blank.
114.It Cm \&%l
115is replaced by the hour (12-hour clock) as a decimal number [1,12];
116single digits are preceded by a blank.
117.It Cm \&%M
118is replaced by the minute as a decimal number [00,59].
119.It Cm %m
120is replaced by the month as a decimal number [01,12].
121.It Cm %n
122is replaced by a newline.
123.It Cm %p
124is replaced by the locale's equivalent of either
125.Dq Tn AM
126or
127.Dq Tn PM .
128.It Cm \&%R
129is replaced by the time in the format
130.Dq Li %H:%M .
131.It Cm \&%r
132is replaced by the locale's representation of 12-hour clock time
133using AM/PM notation.
134.It Cm \&%T
135is replaced by the time in the format
136.Dq Li %H:%M:%S .
137.It Cm \&%t
138is replaced by a tab.
139.It Cm \&%S
140is replaced by the second as a decimal number [00,61].
141.It Cm %s
142is replaced by the number of seconds since the Epoch, UCT (see
143.Xr mktime 3 ) .
144.It Cm \&%U
145is replaced by the week number of the year (Sunday as the first day of
146the week) as a decimal number [00,53].
147.It Cm \&%u
148is replaced by the weekday (Monday as the first day of the week)
149as a decimal number [1,7].
150.It Cm \&%V
151is replaced by the week number of the year (Monday as the first day of
152the week) as a decimal number [01,53].  If the week containing January
1531 has four or more days in the new year, then it is week 1; otherwise
154it is week 53 of the previous year, and the next week is week 1.
155.It Cm \&%W
156is replaced by the week number of the year (Monday as the first day of
157the week) as a decimal number [00,53].
158.It Cm \&%w
159is replaced by the weekday (Sunday as the first day of the week)
160as a decimal number [0,6].
161.It Cm \&%X
162is replaced by the locale's appropriate time representation.
163.It Cm \&%x
164is replaced by the locale's appropriate date representation.
165.It Cm \&%Y
166is replaced by the year with century as a decimal number.
167.It Cm \&%y
168is replaced by the year without century as a decimal number [00,99].
169.It Cm \&%Z
170is replaced by the time zone name.
171.It Cm %%
172is replaced by
173.Ql % .
174.El
175.Sh SEE ALSO
176.Xr date 1 ,
177.Xr ctime 3 ,
178.Xr strptime 3 ,
179.Xr printf 1 ,
180.Xr printf 3
181.Sh STANDARDS
182The
183.Fn strftime
184function
185conforms to
186.St -ansiC .
187The
188.Ql \&%C ,
189.Ql \&%D ,
190.Ql \&%e ,
191.Ql \&%h ,
192.Ql \&%k ,
193.Ql \&%l ,
194.Ql \&%n ,
195.Ql \&%r ,
196.Ql \&%R ,
197.Ql \&%s .
198.Ql \&%t ,
199.Ql \&%T ,
200.Ql \&%u ,
201and
202.Ql \&%V
203conversion specifications are extensions.
204.Sh BUGS
205There is no conversion specification for the phase of the moon.
206