1.\" Copyright (c) 1989, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" the American National Standards Committee X3, on Information 6.\" Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. All advertising materials mentioning features or use of this software 17.\" must display the following acknowledgement: 18.\" This product includes software developed by the University of 19.\" California, Berkeley and its contributors. 20.\" 4. Neither the name of the University nor the names of its contributors 21.\" may be used to endorse or promote products derived from this software 22.\" without specific prior written permission. 23.\" 24.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34.\" SUCH DAMAGE. 35.\" 36.\" @(#)strftime.3 8.1 (Berkeley) 6/4/93 37.\" $FreeBSD$ 38.\" 39.Dd October 4, 1997 40.Dt STRFTIME 3 41.Os 42.Sh NAME 43.Nm strftime 44.Nd format date and time 45.Sh SYNOPSIS 46.Fd #include <time.h> 47.Ft size_t 48.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" 49.Sh DESCRIPTION 50The 51.Fn strftime 52function formats the information from 53.Fa timeptr 54into the buffer 55.Fa buf 56according to the string pointed to by 57.Fa format . 58.Pp 59The 60.Fa format 61string consists of zero or more conversion specifications and 62ordinary characters. 63All ordinary characters are copied directly into the buffer. 64A conversion specification consists of a percent sign 65.Dq Ql % 66and one other character. 67.Pp 68No more than 69.Fa maxsize 70characters will be placed into the array. 71If the total number of resulting characters, including the terminating 72NUL character, is not more than 73.Fa maxsize , 74.Fn strftime 75returns the number of characters in the array, not counting the 76terminating NUL. 77Otherwise, zero is returned and the buffer contents is indeterminate. 78.Pp 79The conversion specifications are copied to the buffer after expansion 80as follows:- 81.Bl -tag -width "xxxx" 82.It Cm \&%A 83is replaced by national representation of the full weekday name. 84.It Cm %a 85is replaced by national representation of 86the abbreviated weekday name, where the abbreviation 87is the first three characters. 88.It Cm \&%B 89is replaced by national representation of the full month name. 90.It Cm %b 91is replaced by national representation of 92the abbreviated month name, where the abbreviation is 93the first three characters. 94.It Cm \&%C 95is replaced by (year / 100) as decimal number; single 96digits are preceded by a zero. 97.It Cm %c 98is replaced by national representation of time and date 99(the format is similar with produced by 100.Xr asctime 3 ) . 101.It Cm \&%D 102is equivalent to 103.Dq Li %m/%d/%y . 104.It Cm %d 105is replaced by the day of the month as a decimal number (01-31). 106.It Cm \&%E* Cm \&%O* 107POSIX locale extensions. 108The sequences 109%Ec %EC %Ex %EX %Ey %EY 110%Od %Oe %OH %OI %Om %OM 111%OS %Ou %OU %OV %Ow %OW %Oy 112are supposed to provide alternate 113representations. 114.Pp 115Additionly %Ef implemented to represent short month name / day 116order of the date, %EF to represent long month name / day 117order 118and %OB to represent alternative months names 119(used standalone, without day mentioned). 120.It Cm %e 121is replaced by the day of month as a decimal number (1-31); single 122digits are preceded by a blank. 123.It Cm \&%G 124is replaced by a year as a decimal number with century. 125This year is the one that contains the greater part of 126the week (Monday as the first day of the week). 127.It Cm %g 128is replaced by the same year as in 129.Dq Li %G , 130but as a decimal number without century (00-99). 131.It Cm \&%H 132is replaced by the hour (24-hour clock) as a decimal number (00-23). 133.It Cm %h 134the same as %b. 135.It Cm \&%I 136is replaced by the hour (12-hour clock) as a decimal number (01-12). 137.It Cm %j 138is replaced by the day of the year as a decimal number (001-366). 139.It Cm %k 140is replaced by the hour (24-hour clock) as a decimal number (0-23); 141single digits are preceded by a blank. 142.It Cm %l 143is replaced by the hour (12-hour clock) as a decimal number (1-12); 144single digits are preceded by a blank. 145.It Cm \&%M 146is replaced by the minute as a decimal number (00-59). 147.It Cm %m 148is replaced by the month as a decimal number (01-12). 149.It Cm %n 150is replaced by a newline. 151.It Cm \&%O* 152the same as %E*. 153.It Cm %p 154is replaced by national representation of either 155"ante meridiem" 156or 157"post meridiem" 158as appropriate. 159.It Cm \&%R 160is equivalent to 161.Dq Li %H:%M . 162.It Cm %r 163is equivalent to 164.Dq Li %I:%M:%S %p . 165.It Cm \&%S 166is replaced by the second as a decimal number (00-60). 167.It Cm %s 168is replaced by the number of seconds since the Epoch, UTC (see 169.Xr mktime 3 ) . 170.It Cm \&%T 171is equivalent to 172.Dq Li %H:%M:%S . 173.It Cm %t 174is replaced by a tab. 175.It Cm \&%U 176is replaced by the week number of the year (Sunday as the first day of 177the week) as a decimal number (00-53). 178.It Cm %u 179is replaced by the weekday (Monday as the first day of the week) 180as a decimal number (1-7). 181.It Cm \&%V 182is replaced by the week number of the year (Monday as the first day of 183the week) as a decimal number (01-53). If the week containing January 1841 has four or more days in the new year, then it is week 1; otherwise 185it is the last week of the previous year, and the next week is week 1. 186.It Cm %v 187is equivalent to 188.Dq Li %e-%b-%Y . 189.It Cm \&%W 190is replaced by the week number of the year (Monday as the first day of 191the week) as a decimal number (00-53). 192.It Cm %w 193is replaced by the weekday (Sunday as the first day of the week) 194as a decimal number (0-6). 195.It Cm \&%X 196is replaced by national representation of the time. 197.It Cm %x 198is replaced by national representation of the date. 199.It Cm \&%Y 200is replaced by the year with century as a decimal number. 201.It Cm %y 202is replaced by the year without century as a decimal number (00-99). 203.It Cm \&%Z 204is replaced by the time zone name. 205.It Cm %+ 206is replaced by national representation of the date and time 207(the format is similar to that produced by 208.Xr date 1 ) . 209.It Cm %% 210is replaced by 211.Ql % . 212.El 213.Sh SEE ALSO 214.Xr date 1 , 215.Xr printf 1 , 216.Xr ctime 3 , 217.Xr printf 3 , 218.Xr strptime 3 219.Sh STANDARDS 220The 221.Fn strftime 222function 223conforms to 224.St -ansiC 225with a lot of extensions including 226.Ql %C , 227.Ql %D , 228.Ql %E* , 229.Ql %e , 230.Ql %G , 231.Ql %g , 232.Ql %h , 233.Ql %k , 234.Ql %l , 235.Ql %n , 236.Ql %O* , 237.Ql \&%R , 238.Ql %r , 239.Ql %s , 240.Ql \&%T , 241.Ql %t , 242.Ql %u , 243.Ql \&%V , 244.Ql %+ . 245 246The peculiar week number and year in the replacements of 247.Ql %G , 248.Ql %g 249and 250.Ql \&%V 251are defined in ISO 8601: 1988. 252 253.Sh BUGS 254There is no conversion specification for the phase of the moon. 255