macro and text revision (-mdoc version 3)
[unix-history] / usr / src / lib / libc / string / strftime.3
CommitLineData
ae59e04c 1.\" Copyright (c) 1989, 1991 The Regents of the University of California.
00b602b8
KB
2.\" All rights reserved.
3.\"
91cff1e1 4.\" %sccs.include.redist.man%
00b602b8 5.\"
ae59e04c 6.\" @(#)strftime.3 5.11 (Berkeley) %G%
00b602b8 7.\"
ae59e04c
CL
8.Dd
9.Dt STRFTIME 3
10.Os
11.Sh NAME
12.Nm strftime
13.Nd format date and time
14.Sh SYNOPSIS
15.Fd #include <sys/types.h>
16.Fd #include <time.h>
17.Fd #include <string.h>
18.Ft size_t
19.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr"
20.Sh DESCRIPTION
00b602b8 21The
ae59e04c 22.Fn strftime
00b602b8 23function formats the information from
ae59e04c 24.Fa timeptr
00b602b8 25into the buffer
ae59e04c 26.Fa buf
00b602b8 27according to the string pointed to by
ae59e04c
CL
28.Fa format .
29.Pp
00b602b8 30The
ae59e04c 31.Fa format
00b602b8
KB
32string consists of zero or more conversion specifications and
33ordinary characters.
34All ordinary characters are copied directly into the buffer.
ae59e04c
CL
35A conversion specification consists of a percent sign
36.Dq Ql %
00b602b8 37and one other character.
ae59e04c 38.Pp
00b602b8 39No more than
ae59e04c 40.Fa maxsize
00b602b8
KB
41characters will be placed into the array.
42If the total number of resulting characters, including the terminating
43null character, is not more than
ae59e04c
CL
44.Fa maxsize ,
45.Fn strftime
00b602b8
KB
46returns the number of characters in the array, not counting the
47terminating null.
48Otherwise, zero is returned.
ae59e04c 49.Pp
00b602b8
KB
50Each conversion specification is replaced by the characters as
51follows which are then copied into the buffer.
ae59e04c
CL
52.Bl -tag -width "xxxx"
53.It Cm \&%A
00b602b8 54is replaced by the full weekday name.
ae59e04c 55.It Cm %a
00b602b8
KB
56is replaced by the abbreviated weekday name, where the abbreviation
57is the first three characters.
ae59e04c 58.It Cm \&%B
00b602b8 59is replaced by the full month name.
ae59e04c 60.It Cm %b or %h
00b602b8
KB
61is replaced by the abbreviated month name, where the abbreviation is
62the first three characters.
ae59e04c
CL
63.It Cm \&%C
64is equivalent to
65.Dq Li %a %b %e %H:%M:%S %Y
66(the format produced by
67.Xr asctime 3 .
68.It Cm %c
69is equivalent to
70.Dq Li %m/%d/%y .
71.It Cm \&%D
72is replaced by the date in the format
73.Dq Ql mm/dd/yy .
74.It Cm %d
00b602b8 75is replaced by the day of the month as a decimal number (01-31).
ae59e04c 76.It Cm %e
14fd63d8
KB
77is replaced by the day of month as a decimal number (1-31); single
78digits are preceded by a blank.
ae59e04c 79.It Cm \&%H
00b602b8 80is replaced by the hour (24-hour clock) as a decimal number (00-23).
ae59e04c 81.It Cm \&%I
00b602b8 82is replaced by the hour (12-hour clock) as a decimal number (01-12).
ae59e04c 83.It Cm %j
00b602b8 84is replaced by the day of the year as a decimal number (001-366).
ae59e04c 85.It Cm %k
14fd63d8
KB
86is replaced by the hour (24-hour clock) as a decimal number (0-23);
87single digits are preceded by a blank.
ae59e04c 88.It Cm %l
4a2abce4 89is replaced by the hour (12-hour clock) as a decimal number (1-12);
14fd63d8 90single digits are preceded by a blank.
ae59e04c 91.It Cm \&%M
e386ba1e 92is replaced by the minute as a decimal number (00-59).
ae59e04c 93.It Cm %m
00b602b8 94is replaced by the month as a decimal number (01-12).
ae59e04c 95.It Cm %n
e386ba1e 96is replaced by a newline.
ae59e04c
CL
97.It Cm %p
98is replaced by either
99.Dq Tn AM
100or
101.Dq Tn PM
102as appropriate.
103.It Cm \&%R
104is equivalent to
105.Dq Li %H:%M
106.It Cm %r
107is equivalent to
108.Dq Li %I:%M:%S %p .
109.It Cm %t
e386ba1e 110is replaced by a tab.
ae59e04c 111.It Cm \&%S
00b602b8 112is replaced by the second as a decimal number (00-60).
ae59e04c 113.It Cm %s
e0b27de7 114is replaced by the number of seconds since the Epoch, UCT (see
ae59e04c
CL
115.Xr mktime 3 ) .
116.It Cm \&%T No or Cm \&%X
117is equivalent to
118.Dq Li %H:%M:%S .
119.It Cm \&%U
00b602b8
KB
120is replaced by the week number of the year (Sunday as the first day of
121the week) as a decimal number (00-53).
ae59e04c 122.It Cm \&%W
00b602b8
KB
123is replaced by the week number of the year (Monday as the first day of
124the week) as a decimal number (00-53).
ae59e04c 125.It Cm %w
00b602b8
KB
126is replaced by the weekday (Sunday as the first day of the week)
127as a decimal number (0-6).
ae59e04c
CL
128.It Cm %x
129is equivalent to
130.Dq Li %m/%d/%y %H:%M:%S .
131.It Cm \&%Y
00b602b8 132is replaced by the year with century as a decimal number.
ae59e04c 133.It Cm %y
00b602b8 134is replaced by the year without century as a decimal number (00-99).
ae59e04c 135.It Cm \&%Z
00b602b8 136is replaced by the time zone name.
ae59e04c
CL
137.It Cm %%
138is replaced by
139.Ql % .
140.El
141.Sh SEE ALSO
142.Xr date 1 ,
143.Xr ctime 3 ,
144.Xr printf 1 ,
145.Xr printf 3
146.Sh STANDARDS
147The
148.Fn strftime
149function
150conforms to
151.St -ansiC .
152The
153.Ql %s
154conversion specification is an extension.
155.Sh BUGS
833f9dd4 156There is no conversion specification for the phase of the moon.