xref: /openbsd-src/lib/libc/time/strftime.3 (revision 8500990981f885cbe5e6a4958549cacc238b5ae6)
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. 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.\"     from: @(#)strftime.3    5.12 (Berkeley) 6/29/91
33.\"	$OpenBSD: strftime.3,v 1.18 2003/06/02 20:18:40 millert Exp $
34.\"
35.Dd January 18, 1998
36.Dt STRFTIME 3
37.Os
38.Sh NAME
39.Nm strftime
40.Nd format date and time
41.Sh SYNOPSIS
42.Fd #include <time.h>
43.Ft size_t
44.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
45.Sh DESCRIPTION
46The
47.Fn strftime
48function formats the information from
49.Fa timeptr
50into the buffer
51.Fa buf
52according to the string pointed to by
53.Fa format .
54.Pp
55The
56.Fa format
57string consists of zero or more conversion specifications and
58ordinary characters.
59All ordinary characters are copied directly into the buffer.
60A conversion specification consists of a percent sign
61.Ql %
62and one other character.
63.Pp
64No more than
65.Fa maxsize
66characters will be placed into the array.
67If the total number of resulting characters, including the terminating
68NUL character, is not more than
69.Fa maxsize ,
70.Fn strftime
71returns the number of characters in the array, not counting the
72terminating NUL.
73Otherwise, zero is returned.
74.Pp
75Each conversion specification is replaced by the characters as
76follows which are then copied into the buffer.
77.Bl -tag -width "xxxx"
78.It Cm \&%A
79is replaced by the locale's full weekday name.
80.It Cm \&%a
81is replaced by the locale's abbreviated weekday name.
82.It Cm \&%B
83is replaced by the locale's full month name.
84.It Cm \&%b No or Cm \&%h
85is replaced by the locale's abbreviated month name.
86.It Cm \&%C
87is replaced by the century (a year divided by 100 and truncated to an integer)
88as a decimal number (00-99).
89.It Cm \&%c
90is replaced by the locale's appropriate date and time representation.
91.It Cm \&%D
92is replaced by the date in the format
93.Dq Li %m/%d/%y .
94.It Cm \&%d
95is replaced by the day of the month as a decimal number (01-31).
96.It Cm \&%e
97is replaced by the day of month as a decimal number (1-31);
98single digits are preceded by a blank.
99.It Cm \&%F
100is replaced by the date in the format
101.Dq Li %Y-%m-%d .
102.It Cm \&%G
103is replaced by the ISO 8601 year with century as a decimal number.
104.It Cm \&%g
105is replaced by the ISO 8601 year without century as a decimal number (00-99).
106.It Cm \&%H
107is replaced by the hour (24-hour clock) as a decimal number (00-23).
108.It Cm \&%I
109is replaced by the hour (12-hour clock) as a decimal number (01-12).
110.It Cm \&%j
111is replaced by the day of the year as a decimal number (001-366).
112.It Cm \&%k
113is replaced by the hour (24-hour clock) as a decimal number (0-23);
114single digits are preceded by a blank.
115.It Cm \&%l
116is replaced by the hour (12-hour clock) as a decimal number (1-12);
117single digits are preceded by a blank.
118.It Cm \&%M
119is replaced by the minute as a decimal number (00-59).
120.It Cm %m
121is replaced by the month as a decimal number (01-12).
122.It Cm %n
123is replaced by a newline.
124.It Cm %p
125is replaced by the locale's equivalent of either
126.Dq Tn AM
127or
128.Dq Tn PM .
129.It Cm \&%R
130is replaced by the time in the format
131.Dq Li %H:%M .
132.It Cm \&%r
133is replaced by the locale's representation of 12-hour clock time
134using AM/PM notation.
135.It Cm \&%S
136is replaced by the second as a decimal number (00-61).
137The range of
138seconds is (00-61) instead of (00-59) to allow for the periodic occurrence
139of leap seconds and double leap seconds.
140.It Cm %s
141is replaced by the number of seconds since the Epoch, UTC (see
142.Xr mktime 3 ) .
143.It Cm \&%T
144is replaced by the time in the format
145.Dq Li %H:%M:%S .
146.It Cm \&%t
147is replaced by a tab.
148.It Cm \&%U
149is replaced by the week number of the year (Sunday as the first day of
150the week) as a decimal number (00-53).
151.It Cm \&%u
152is replaced by the weekday (Monday as the first day of the week)
153as a decimal number (1-7).
154.It Cm \&%V
155is replaced by the week number of the year (Monday as the first day of
156the week) as a decimal number (01-53).
157If the week containing January
1581 has four or more days in the new year, then it is week 1; otherwise
159it is week 53 of the previous year, and the next week is week 1.
160.It Cm \&%W
161is replaced by the week number of the year (Monday as the first day of
162the week) as a decimal number (00-53).
163.It Cm \&%w
164is replaced by the weekday (Sunday as the first day of the week)
165as a decimal number (0-6).
166.It Cm \&%X
167is replaced by the locale's appropriate time representation.
168.It Cm \&%x
169is replaced by the locale's appropriate date representation.
170.It Cm \&%Y
171is replaced by the year with century as a decimal number.
172.It Cm \&%y
173is replaced by the year without century as a decimal number (00-99).
174.It Cm \&%Z
175is replaced by the time zone name,
176or by the empty string if this is not determinable.
177.It Cm \&%z
178is replaced by the offset from UTC in the format
179.Dq Li +HHMM
180or
181.Dq Li -HHMM
182as appropriate, with positive values representing locations east
183of Greenwich, or by the empty string if this is not determinable.
184.It Cm %%
185is replaced by
186.Ql % .
187.It Cm %+
188is replaced by the date and time in
189.Xr date 1
190format.
191.El
192.Sh SEE ALSO
193.Xr date 1 ,
194.Xr printf 1 ,
195.Xr ctime 3 ,
196.Xr getenv 3 ,
197.Xr printf 3 ,
198.Xr strptime 3 ,
199.Xr time 3 ,
200.Xr tzset 3 ,
201.Xr tzfile 5
202.Sh STANDARDS
203The
204.Fn strftime
205function
206conforms to
207.St -ansiC .
208.Pp
209The
210.Ql \&%G ,
211.Ql \&%g ,
212.Ql \&%k ,
213.Ql \&%l ,
214.Ql \&%s ,
215and
216.Ql \&%+
217conversion specifications are extensions.
218.Pp
219Use of the ISO 8601 conversions may produce non-intuitive results.
220Week 01 of a year is per definition the first week which has the Thursday
221in this year, which is equivalent to the week which contains the fourth
222day of January.
223In other words, the first week of a new year is the week which has the
224majority of its days in the new year.
225Week 01 might also contain days from the previous year and the week
226before week 01 of a year is the last week (52 or 53) of the previous
227year even if it contains days from the new year.
228A week starts with Monday (day 1) and ends with Sunday (day 7).
229For example, the first week of the year 1997 lasts from
2301996-12-30 to 1997-01-05.
231.Sh BUGS
232There is no conversion specification for the phase of the moon.
233.Pp
234Note that while this implementation of
235.Fn strftime
236will always NUL terminate
237.Fa buf ,
238other implementations may not do so when
239.Fa maxsiz
240is not large enough to store the entire time string.
241The contents of
242.Fa buf
243are implementation specific in this case.
244.\" @(#)newstrftime.3   7.14
245