xref: /netbsd/lib/libc/time/strftime.3 (revision c4a72b64)
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.17 2002/11/10 19:51:47 kleink Exp $
38.\"
39.Dd August 18, 2002
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 \*[Lt]time.h\*[Gt]
49.Ft size_t
50.Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict 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 and the contents of the array are undefined.
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 \&%F
106is replaced by the time in the format
107.Dq Li %Y-%m-%d
108(the ISO 8601 date format).
109.It Cm \&%G
110is replaced by the ISO 8601 year with century as a decimal number.
111.TP
112.It Cm \&%g
113is replaced by the ISO 8601 year without century as a decimal number (00-99).
114This is the year that includes the greater part of the week.
115(Monday as the first day of a week).
116See also the
117.Ql \&%V
118conversion specification.
119.TP
120.It Cm \&%H
121is replaced by the hour (24-hour clock) as a decimal number [00,23].
122.It Cm \&%I
123is replaced by the hour (12-hour clock) as a decimal number [01,12].
124.It Cm \&%j
125is replaced by the day of the year as a decimal number [001,366].
126.It Cm \&%k
127is replaced by the hour (24-hour clock) as a decimal number [0,23];
128single digits are preceded by a blank.
129.It Cm \&%l
130is replaced by the hour (12-hour clock) as a decimal number [1,12];
131single digits are preceded by a blank.
132.It Cm \&%M
133is replaced by the minute as a decimal number [00,59].
134.It Cm %m
135is replaced by the month as a decimal number [01,12].
136.It Cm %n
137is replaced by a newline.
138.It Cm %p
139is replaced by the locale's equivalent of either
140.Dq Tn AM
141or
142.Dq Tn PM .
143.It Cm \&%R
144is replaced by the time in the format
145.Dq Li %H:%M .
146.It Cm \&%r
147is replaced by the locale's representation of 12-hour clock time
148using AM/PM notation.
149.It Cm \&%S
150is replaced by the second as a decimal number [00,61].
151The range of
152seconds is (00-61) instead of (00-59) to allow for the periodic occurance
153of leap seconds and double leap seconds.
154.It Cm %s
155is replaced by the number of seconds since the Epoch, UTC (see
156.Xr mktime 3 ) .
157.It Cm \&%T
158is replaced by the time in the format
159.Dq Li %H:%M:%S .
160.It Cm \&%t
161is replaced by a tab.
162.It Cm \&%U
163is replaced by the week number of the year (Sunday as the first day of
164the week) as a decimal number [00,53].
165.It Cm \&%u
166is replaced by the weekday (Monday as the first day of the week)
167as a decimal number [1,7].
168.It Cm \&%V
169is replaced by the week number of the year (Monday as the first day of
170the week) as a decimal number [01,53]. According to ISO 8601 the week
171containing January 1 is week 1 if it has four or more days in the new year,
172otherwise it is week 53 of the previous year, and the next week is week 1.
173The year is given by the
174.Ql \&%G
175conversion specification.
176.It Cm \&%W
177is replaced by the week number of the year (Monday as the first day of
178the week) as a decimal number [00,53].
179.It Cm \&%w
180is replaced by the weekday (Sunday as the first day of the week)
181as a decimal number [0,6].
182.It Cm \&%X
183is replaced by the locale's appropriate time representation.
184.It Cm \&%x
185is replaced by the locale's appropriate date representation.
186.It Cm \&%Y
187is replaced by the year with century as a decimal number.
188.It Cm \&%y
189is replaced by the year without century as a decimal number [00,99].
190.It Cm \&%Z
191is replaced by the time zone name.
192.It Cm \&%z
193is replaced by the offset from ITC in the ISO 8601 format
194.Dq Li [-]hhmm .
195.It Cm %%
196is replaced by
197.Ql % .
198.El
199.Sh SEE ALSO
200.Xr date 1 ,
201.Xr printf 1 ,
202.Xr ctime 3 ,
203.Xr printf 3 ,
204.Xr strptime 3
205.Sh STANDARDS
206The
207.Fn strftime
208function
209conforms to
210.St -isoC99 .
211The
212.Ql \&%C ,
213.Ql \&%D ,
214.Ql \&%e ,
215.Ql \&%g ,
216.Ql \&%G ,
217.Ql \&%h ,
218.Ql \&%k ,
219.Ql \&%l ,
220.Ql \&%n ,
221.Ql \&%r ,
222.Ql \&%R ,
223.Ql \&%s ,
224.Ql \&%t ,
225.Ql \&%T ,
226.Ql \&%u ,
227and
228.Ql \&%V
229conversion specifications are extensions.
230.Pp
231Use of the ISO 8601 conversions may produce non-intuitive results.
232Week 01 of a year is per definition the first week which has the Thursday
233in this year, which is equivalent to the week which contains the fourth
234day of January.
235In other words, the first week of a new year is the week which has the
236majority of its days in the new year.
237Week 01 might also contain days from the previous year and the week
238before week 01 of a year is the last week (52 or 53) of the previous
239year even if it contains days from the new year.
240A week starts with Monday (day 1) and ends with Sunday (day 7).
241For example, the first week of the year 1997 lasts from
2421996-12-30 to 1997-01-05.
243.Sh BUGS
244There is no conversion specification for the phase of the moon.
245