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.\" %sccs.include.redist.man% 9.\" 10.\" @(#)strftime.3 8.1 (Berkeley) 06/04/93 11.\" 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 25The 26.Fn strftime 27function formats the information from 28.Fa timeptr 29into the buffer 30.Fa buf 31according to the string pointed to by 32.Fa format . 33.Pp 34The 35.Fa 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 40.Dq Ql % 41and one other character. 42.Pp 43No more than 44.Fa maxsize 45characters will be placed into the array. 46If the total number of resulting characters, including the terminating 47null character, is not more than 48.Fa maxsize , 49.Fn strftime 50returns the number of characters in the array, not counting the 51terminating null. 52Otherwise, zero is returned. 53.Pp 54Each conversion specification is replaced by the characters as 55follows which are then copied into the buffer. 56.Bl -tag -width "xxxx" 57.It Cm \&%A 58is replaced by the full weekday name. 59.It Cm %a 60is replaced by the abbreviated weekday name, where the abbreviation 61is the first three characters. 62.It Cm \&%B 63is replaced by the full month name. 64.It Cm %b or %h 65is replaced by the abbreviated month name, where the abbreviation is 66the first three characters. 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 79is replaced by the day of the month as a decimal number (01-31). 80.It Cm %e 81is replaced by the day of month as a decimal number (1-31); single 82digits are preceded by a blank. 83.It Cm \&%H 84is replaced by the hour (24-hour clock) as a decimal number (00-23). 85.It Cm \&%I 86is replaced by the hour (12-hour clock) as a decimal number (01-12). 87.It Cm %j 88is replaced by the day of the year as a decimal number (001-366). 89.It Cm %k 90is replaced by the hour (24-hour clock) as a decimal number (0-23); 91single digits are preceded by a blank. 92.It Cm %l 93is replaced by the hour (12-hour clock) as a decimal number (1-12); 94single digits are preceded by a blank. 95.It Cm \&%M 96is replaced by the minute as a decimal number (00-59). 97.It Cm %m 98is replaced by the month as a decimal number (01-12). 99.It Cm %n 100is replaced by a newline. 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 114is replaced by a tab. 115.It Cm \&%S 116is replaced by the second as a decimal number (00-60). 117.It Cm %s 118is replaced by the number of seconds since the Epoch, UCT (see 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 124is replaced by the week number of the year (Sunday as the first day of 125the week) as a decimal number (00-53). 126.It Cm \&%W 127is replaced by the week number of the year (Monday as the first day of 128the week) as a decimal number (00-53). 129.It Cm %w 130is replaced by the weekday (Sunday as the first day of the week) 131as a decimal number (0-6). 132.It Cm %x 133is equivalent to 134.Dq Li %m/%d/%y %H:%M:%S . 135.It Cm \&%Y 136is replaced by the year with century as a decimal number. 137.It Cm %y 138is replaced by the year without century as a decimal number (00-99). 139.It Cm \&%Z 140is replaced by the time zone name. 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 160There is no conversion specification for the phase of the moon. 161