Commit | Line | Data |
---|---|---|
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 | 21 | The |
ae59e04c | 22 | .Fn strftime |
00b602b8 | 23 | function formats the information from |
ae59e04c | 24 | .Fa timeptr |
00b602b8 | 25 | into the buffer |
ae59e04c | 26 | .Fa buf |
00b602b8 | 27 | according to the string pointed to by |
ae59e04c CL |
28 | .Fa format . |
29 | .Pp | |
00b602b8 | 30 | The |
ae59e04c | 31 | .Fa format |
00b602b8 KB |
32 | string consists of zero or more conversion specifications and |
33 | ordinary characters. | |
34 | All ordinary characters are copied directly into the buffer. | |
ae59e04c CL |
35 | A conversion specification consists of a percent sign |
36 | .Dq Ql % | |
00b602b8 | 37 | and one other character. |
ae59e04c | 38 | .Pp |
00b602b8 | 39 | No more than |
ae59e04c | 40 | .Fa maxsize |
00b602b8 KB |
41 | characters will be placed into the array. |
42 | If the total number of resulting characters, including the terminating | |
43 | null character, is not more than | |
ae59e04c CL |
44 | .Fa maxsize , |
45 | .Fn strftime | |
00b602b8 KB |
46 | returns the number of characters in the array, not counting the |
47 | terminating null. | |
48 | Otherwise, zero is returned. | |
ae59e04c | 49 | .Pp |
00b602b8 KB |
50 | Each conversion specification is replaced by the characters as |
51 | follows which are then copied into the buffer. | |
ae59e04c CL |
52 | .Bl -tag -width "xxxx" |
53 | .It Cm \&%A | |
00b602b8 | 54 | is replaced by the full weekday name. |
ae59e04c | 55 | .It Cm %a |
00b602b8 KB |
56 | is replaced by the abbreviated weekday name, where the abbreviation |
57 | is the first three characters. | |
ae59e04c | 58 | .It Cm \&%B |
00b602b8 | 59 | is replaced by the full month name. |
ae59e04c | 60 | .It Cm %b or %h |
00b602b8 KB |
61 | is replaced by the abbreviated month name, where the abbreviation is |
62 | the first three characters. | |
ae59e04c CL |
63 | .It Cm \&%C |
64 | is 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 | |
69 | is equivalent to | |
70 | .Dq Li %m/%d/%y . | |
71 | .It Cm \&%D | |
72 | is replaced by the date in the format | |
73 | .Dq Ql mm/dd/yy . | |
74 | .It Cm %d | |
00b602b8 | 75 | is replaced by the day of the month as a decimal number (01-31). |
ae59e04c | 76 | .It Cm %e |
14fd63d8 KB |
77 | is replaced by the day of month as a decimal number (1-31); single |
78 | digits are preceded by a blank. | |
ae59e04c | 79 | .It Cm \&%H |
00b602b8 | 80 | is replaced by the hour (24-hour clock) as a decimal number (00-23). |
ae59e04c | 81 | .It Cm \&%I |
00b602b8 | 82 | is replaced by the hour (12-hour clock) as a decimal number (01-12). |
ae59e04c | 83 | .It Cm %j |
00b602b8 | 84 | is replaced by the day of the year as a decimal number (001-366). |
ae59e04c | 85 | .It Cm %k |
14fd63d8 KB |
86 | is replaced by the hour (24-hour clock) as a decimal number (0-23); |
87 | single digits are preceded by a blank. | |
ae59e04c | 88 | .It Cm %l |
4a2abce4 | 89 | is replaced by the hour (12-hour clock) as a decimal number (1-12); |
14fd63d8 | 90 | single digits are preceded by a blank. |
ae59e04c | 91 | .It Cm \&%M |
e386ba1e | 92 | is replaced by the minute as a decimal number (00-59). |
ae59e04c | 93 | .It Cm %m |
00b602b8 | 94 | is replaced by the month as a decimal number (01-12). |
ae59e04c | 95 | .It Cm %n |
e386ba1e | 96 | is replaced by a newline. |
ae59e04c CL |
97 | .It Cm %p |
98 | is replaced by either | |
99 | .Dq Tn AM | |
100 | or | |
101 | .Dq Tn PM | |
102 | as appropriate. | |
103 | .It Cm \&%R | |
104 | is equivalent to | |
105 | .Dq Li %H:%M | |
106 | .It Cm %r | |
107 | is equivalent to | |
108 | .Dq Li %I:%M:%S %p . | |
109 | .It Cm %t | |
e386ba1e | 110 | is replaced by a tab. |
ae59e04c | 111 | .It Cm \&%S |
00b602b8 | 112 | is replaced by the second as a decimal number (00-60). |
ae59e04c | 113 | .It Cm %s |
e0b27de7 | 114 | is 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 | |
117 | is equivalent to | |
118 | .Dq Li %H:%M:%S . | |
119 | .It Cm \&%U | |
00b602b8 KB |
120 | is replaced by the week number of the year (Sunday as the first day of |
121 | the week) as a decimal number (00-53). | |
ae59e04c | 122 | .It Cm \&%W |
00b602b8 KB |
123 | is replaced by the week number of the year (Monday as the first day of |
124 | the week) as a decimal number (00-53). | |
ae59e04c | 125 | .It Cm %w |
00b602b8 KB |
126 | is replaced by the weekday (Sunday as the first day of the week) |
127 | as a decimal number (0-6). | |
ae59e04c CL |
128 | .It Cm %x |
129 | is equivalent to | |
130 | .Dq Li %m/%d/%y %H:%M:%S . | |
131 | .It Cm \&%Y | |
00b602b8 | 132 | is replaced by the year with century as a decimal number. |
ae59e04c | 133 | .It Cm %y |
00b602b8 | 134 | is replaced by the year without century as a decimal number (00-99). |
ae59e04c | 135 | .It Cm \&%Z |
00b602b8 | 136 | is replaced by the time zone name. |
ae59e04c CL |
137 | .It Cm %% |
138 | is 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 | |
147 | The | |
148 | .Fn strftime | |
149 | function | |
150 | conforms to | |
151 | .St -ansiC . | |
152 | The | |
153 | .Ql %s | |
154 | conversion specification is an extension. | |
155 | .Sh BUGS | |
833f9dd4 | 156 | There is no conversion specification for the phase of the moon. |