1.\" Copyright (c) 1989, 1991 The Regents of the University of California. 2.\" 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.\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 37.\" $OpenBSD: strftime.3,v 1.13 2001/07/15 20:13:45 nate Exp $ 38.\" 39.Dd January 18, 1998 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.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. 78.Pp 79Each conversion specification is replaced by the characters as 80follows which are then copied into the buffer. 81.Bl -tag -width "xxxx" 82.It Cm \&%A 83is replaced by the locale's full weekday name. 84.It Cm \&%a 85is replaced by the locale's abbreviated weekday name. 86.It Cm \&%B 87is replaced by the locale's full month name. 88.It Cm \&%b No or Cm \&%h 89is replaced by the locale's abbreviated month name. 90.It Cm \&%C 91is replaced by the century (a year divided by 100 and truncated to an integer) 92as a decimal number (00-99). 93.It Cm \&%c 94is replaced by the locale's appropriate date and time representation. 95.It Cm \&%D 96is replaced by the date in the format 97.Dq Li %m/%d/%y . 98.It Cm \&%d 99is replaced by the day of the month as a decimal number (01-31). 100.It Cm \&%e 101is replaced by the day of month as a decimal number (1-31); 102single digits are preceded by a blank. 103.It Cm \&%F 104is replaced by the date in the format 105.Dq Li %Y-%m-%d . 106.It Cm \&%G 107is replaced by the ISO 8601 year with century as a decimal number. 108.It Cm \&%g 109is replaced by the ISO 8601 year without century as a decimal number (00-99). 110.It Cm \&%H 111is replaced by the hour (24-hour clock) as a decimal number (00-23). 112.It Cm \&%I 113is replaced by the hour (12-hour clock) as a decimal number (01-12). 114.It Cm \&%j 115is replaced by the day of the year as a decimal number (001-366). 116.It Cm \&%k 117is replaced by the hour (24-hour clock) as a decimal number (0-23); 118single digits are preceded by a blank. 119.It Cm \&%l 120is replaced by the hour (12-hour clock) as a decimal number (1-12); 121single digits are preceded by a blank. 122.It Cm \&%M 123is replaced by the minute as a decimal number (00-59). 124.It Cm %m 125is replaced by the month as a decimal number (01-12). 126.It Cm %n 127is replaced by a newline. 128.It Cm %p 129is replaced by the locale's equivalent of either 130.Dq Tn AM 131or 132.Dq Tn PM . 133.It Cm \&%R 134is replaced by the time in the format 135.Dq Li %H:%M . 136.It Cm \&%r 137is replaced by the locale's representation of 12-hour clock time 138using AM/PM notation. 139.It Cm \&%S 140is replaced by the second as a decimal number (00-61). The range of 141seconds is (00-61) instead of (00-59) to allow for the periodic occurance 142of leap seconds and double leap seconds. 143.It Cm %s 144is replaced by the number of seconds since the Epoch, UTC (see 145.Xr mktime 3 ) . 146.It Cm \&%T 147is replaced by the time in the format 148.Dq Li %H:%M:%S . 149.It Cm \&%t 150is replaced by a tab. 151.It Cm \&%U 152is replaced by the week number of the year (Sunday as the first day of 153the week) as a decimal number (00-53). 154.It Cm \&%u 155is replaced by the weekday (Monday as the first day of the week) 156as a decimal number (1-7). 157.It Cm \&%V 158is replaced by the week number of the year (Monday as the first day of 159the week) as a decimal number (01-53). 160If the week containing January 1611 has four or more days in the new year, then it is week 1; otherwise 162it is week 53 of the previous year, and the next week is week 1. 163.It Cm \&%W 164is replaced by the week number of the year (Monday as the first day of 165the week) as a decimal number (00-53). 166.It Cm \&%w 167is replaced by the weekday (Sunday as the first day of the week) 168as a decimal number (0-6). 169.It Cm \&%X 170is replaced by the locale's appropriate time representation. 171.It Cm \&%x 172is replaced by the locale's appropriate date representation. 173.It Cm \&%Y 174is replaced by the year with century as a decimal number. 175.It Cm \&%y 176is replaced by the year without century as a decimal number (00-99). 177.It Cm \&%Z 178is replaced by the time zone name, 179or by the empty string if this is not determinable. 180.It Cm \&%z 181is replaced by the offset from UTC in the format 182.Dq Li +HHMM 183or 184.Dq Li -HHMM 185as appropriate, with positive values representing locations east 186of Greenwich, or by the empty string if this is not determinable. 187.It Cm %% 188is replaced by 189.Ql % . 190.It Cm %+ 191is replaced by the date and time in 192.Xr date 1 193format. 194.El 195.Sh SEE ALSO 196.Xr date 1 , 197.Xr printf 1 , 198.Xr ctime 3 , 199.Xr getenv 3 , 200.Xr printf 3 , 201.Xr strptime 3 , 202.Xr time 3 , 203.Xr tzset 3 , 204.Xr tzfile 5 205.Sh STANDARDS 206The 207.Fn strftime 208function 209conforms to 210.St -ansiC . 211.Pp 212The 213.Ql \&%G , 214.Ql \&%g , 215.Ql \&%k , 216and 217.Ql \&%l 218conversion specifications are extensions. 219.Pp 220Use of the ISO 8601 conversions may produce non-intuitive results. 221Week 01 of a year is per definition the first week which has the Thursday 222in this year, which is equivalent to the week which contains the fourth 223day of January. 224In other words, the first week of a new year is the week which has the 225majority of its days in the new year. 226Week 01 might also contain days from the previous year and the week 227before week 01 of a year is the last week (52 or 53) of the previous 228year even if it contains days from the new year. 229A week starts with Monday (day 1) and ends with Sunday (day 7). 230For example, the first week of the year 1997 lasts from 2311996-12-30 to 1997-01-05. 232.Sh BUGS 233There is no conversion specification for the phase of the moon. 234.Pp 235Note that while this implementation of 236.Fn strftime 237will always NUL terminate 238.Fa buf , 239other implementations may not do so when 240.Fa maxsiz 241is not large enough to store the entire time string. 242The contents of 243.Fa buf 244are implementation specific in this case. 245.\" @(#)newstrftime.3 7.14 246