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