1STRFTIME(3) Library Functions Manual STRFTIME(3)
2
3
4
6 strftime - format date and time
7
9 #include <sys/types.h>
10 #include <time.h>
11 #include <string.h>
12
13 size_t strftime(buf, maxsize, format, timeptr)
14 char *buf;
15 size_t maxsize;
16 char *format;
17 struct tm *timeptr;
18
20 The strftime() function formats the information from timeptr into the
21 buffer buf according to the string pointed to by format.
22
23 The format string consists of zero or more conversion specifications
24 and ordinary characters. All ordinary characters are copied directly
25 into the buffer. A conversion specification consists of a percent sign
26 ``%'' and one other character.
27
28 No more than maxsize characters will be placed into the array. If the
29 total number of resulting characters, including the terminating null
30 character, is not more than maxsize, strftime() returns the number of
31 characters in the array, not counting the terminating null. Otherwise,
32 zero is returned.
33
34 Each conversion specification is replaced by the characters as follows
35 which are then copied into the buffer.
36
37 %A is replaced by the full weekday name.
38
39 %a is replaced by the abbreviated weekday name, where the abbrevia‐
40 tion is the first three characters.
41
42 %B is replaced by the full month name.
43
44 %b or %h
45 is replaced by the abbreviated month name, where the abbrevia‐
46 tion is the first three characters.
47
48 %C is equivalent to ``%a %b %e %H:%M:%S %Y'' (the format produced
49 by asctime(3)).
50
51 %c is equivalent to ``%m/%d/%y''.
52
53 %D is replaced by the date in the format ``mm/dd/yy''.
54
55 %d is replaced by the day of the month as a decimal number (01-31).
56
57 %e is replaced by the day of month as a decimal number (1-31); sin‐
58 gle digits are preceded by a blank.
59
60 %H is replaced by the hour (24-hour clock) as a decimal number
61 (00-23).
62
63 %I is replaced by the hour (12-hour clock) as a decimal number
64 (01-12).
65
66 %j is replaced by the day of the year as a decimal number
67 (001-366).
68
69 %k is replaced by the hour (24-hour clock) as a decimal number
70 (0-23); single digits are preceded by a blank.
71
72 %l is replaced by the hour (12-hour clock) as a decimal number
73 (1-12); single digits are preceded by a blank.
74
75 %M is replaced by the minute as a decimal number (00-59).
76
77 %m is replaced by the month as a decimal number (01-12).
78
79 %n is replaced by a newline.
80
81 %p is replaced by either ``AM'' or ``PM'' as appropriate.
82
83 %R is equivalent to ``%H:%M''
84
85 %r is equivalent to ``%I:%M:%S %p'' .
86
87 %t is replaced by a tab.
88
89 %S is replaced by the second as a decimal number (00-60).
90
91 %T or %X
92 is equivalent to "%H:%M:%S" .
93
94 %U is replaced by the week number of the year (Sunday as the first
95 day of the week) as a decimal number (00-53).
96
97 %W is replaced by the week number of the year (Monday as the first
98 day of the week) as a decimal number (00-53).
99
100 %w is replaced by the weekday (Sunday as the first day of the week)
101 as a decimal number (0-6).
102
103 %x is equivalent to ``%m/%d/%y %H:%M:%S'' .
104
105 %Y is replaced by the year with century as a decimal number.
106
107 %y is replaced by the year without century as a decimal number
108 (00-99).
109
110 %Z is replaced by the time zone name.
111
112 %% is replaced by `%' .
113
115 date(1), ctime(3), printf(1), printf(3)
116
118 The strftime() function conforms to ANSI X C3.159-1989(``ANSI C'').
119
121 There is no conversion specification for the phase of the moon.
122
123
124
1254.2 Berkeley Distribution April 1, 1995 STRFTIME(3)