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