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. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91 33.\" $NetBSD: strftime.3,v 1.22 2004/04/14 21:59:39 kleink Exp $ 34.\" 35.Dd April 14, 2004 36.Dt STRFTIME 3 37.Os 38.Sh NAME 39.Nm strftime 40.Nd format date and time 41.Sh LIBRARY 42.Lb libc 43.Sh SYNOPSIS 44.In time.h 45.Ft size_t 46.Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr" 47.Sh DESCRIPTION 48The 49.Fn strftime 50function formats the information from 51.Fa timeptr 52into the buffer 53.Fa buf 54according to the string pointed to by 55.Fa format . 56.Pp 57The 58.Fa format 59string consists of zero or more conversion specifications and 60ordinary characters. 61All ordinary characters are copied directly into the buffer. 62A conversion specification consists of a percent sign 63.Ql % 64and one other character. 65.Pp 66No more than 67.Fa maxsize 68characters will be placed into the array. 69If the total number of resulting characters, including the terminating 70null character, is not more than 71.Fa maxsize , 72.Fn strftime 73returns the number of characters in the array, not counting the 74terminating null. 75Otherwise, zero is returned and the contents of the array are undefined. 76.Pp 77Each conversion specification is replaced by the characters as 78follows which are then copied into the buffer. 79.Bl -tag -width "xxxx" 80.It Cm \&%A 81is replaced by the locale's full weekday name. 82.It Cm %a 83is replaced by the locale's abbreviated weekday name. 84.It Cm \&%B 85is replaced by the locale's full month name. 86.It Cm \&%b No or Cm \&%h 87is replaced by the locale's abbreviated month name. 88.It Cm \&%C 89is replaced by the century (a year divided by 100 and truncated to an integer) 90as a decimal number [00,99]. 91.It Cm \&%c 92is replaced by the locale's appropriate date and time representation. 93.It Cm \&%D 94is replaced by the date in the format 95.Dq Li %m/%d/%y . 96.It Cm \&%d 97is replaced by the day of the month as a decimal number [01,31]. 98.It Cm \&%e 99is replaced by the day of month as a decimal number [1,31]; 100single digits are preceded by a blank. 101.It Cm \&%F 102is replaced by the date in the format 103.Dq Li %Y-%m-%d 104(the ISO 8601 date format). 105.It Cm \&%G 106is replaced by the ISO 8601 year with century as a decimal number. 107.TP 108.It Cm \&%g 109is replaced by the ISO 8601 year without century as a decimal number (00-99). 110This is the year that includes the greater part of the week. 111(Monday as the first day of a week). 112See also the 113.Ql \&%V 114conversion specification. 115.TP 116.It Cm \&%H 117is replaced by the hour (24-hour clock) as a decimal number [00,23]. 118.It Cm \&%I 119is replaced by the hour (12-hour clock) as a decimal number [01,12]. 120.It Cm \&%j 121is replaced by the day of the year as a decimal number [001,366]. 122.It Cm \&%k 123is replaced by the hour (24-hour clock) as a decimal number [0,23]; 124single digits are preceded by a blank. 125.It Cm \&%l 126is replaced by the hour (12-hour clock) as a decimal number [1,12]; 127single digits are preceded by a blank. 128.It Cm \&%M 129is replaced by the minute as a decimal number [00,59]. 130.It Cm %m 131is replaced by the month as a decimal number [01,12]. 132.It Cm %n 133is replaced by a newline. 134.It Cm %p 135is replaced by the locale's equivalent of either 136.Dq Tn AM 137or 138.Dq Tn PM . 139.It Cm \&%R 140is replaced by the time in the format 141.Dq Li %H:%M . 142.It Cm \&%r 143is replaced by the locale's representation of 12-hour clock time 144using AM/PM notation. 145.It Cm \&%S 146is replaced by the second as a decimal number [00,61]. 147The range of 148seconds is (00-61) instead of (00-59) to allow for the periodic occurance 149of leap seconds and double leap seconds. 150.It Cm %s 151is replaced by the number of seconds since the Epoch, UTC (see 152.Xr mktime 3 ) . 153.It Cm \&%T 154is replaced by the time in the format 155.Dq Li %H:%M:%S . 156.It Cm \&%t 157is replaced by a tab. 158.It Cm \&%U 159is replaced by the week number of the year (Sunday as the first day of 160the week) as a decimal number [00,53]. 161.It Cm \&%u 162is replaced by the weekday (Monday as the first day of the week) 163as a decimal number [1,7]. 164.It Cm \&%V 165is replaced by the week number of the year (Monday as the first day of 166the week) as a decimal number [01,53]. According to ISO 8601 the week 167containing January 1 is week 1 if it has four or more days in the new year, 168otherwise it is week 53 of the previous year, and the next week is week 1. 169The year is given by the 170.Ql \&%G 171conversion specification. 172.It Cm \&%v 173is replaced by the date in the format 174.Dq Li %e-%b-%Y . 175.It Cm \&%W 176is replaced by the week number of the year (Monday as the first day of 177the week) as a decimal number [00,53]. 178.It Cm \&%w 179is replaced by the weekday (Sunday as the first day of the week) 180as a decimal number [0,6]. 181.It Cm \&%X 182is replaced by the locale's appropriate time representation. 183.It Cm \&%x 184is replaced by the locale's appropriate date representation. 185.It Cm \&%Y 186is replaced by the year with century as a decimal number. 187.It Cm \&%y 188is replaced by the year without century as a decimal number [00,99]. 189.It Cm \&%Z 190is replaced by the time zone name. 191.It Cm \&%z 192is replaced by the offset from ITC in the ISO 8601 format 193.Dq Li [-]hhmm . 194.It Cm %% 195is replaced by 196.Ql % . 197.El 198.Sh SEE ALSO 199.Xr date 1 , 200.Xr printf 1 , 201.Xr ctime 3 , 202.Xr printf 3 , 203.Xr strptime 3 204.Sh STANDARDS 205The 206.Fn strftime 207function 208conforms to 209.St -isoC-99 . 210The 211.Ql \&%C , 212.Ql \&%D , 213.Ql \&%e , 214.Ql \&%g , 215.Ql \&%G , 216.Ql \&%h , 217.Ql \&%k , 218.Ql \&%l , 219.Ql \&%n , 220.Ql \&%r , 221.Ql \&%R , 222.Ql \&%s , 223.Ql \&%t , 224.Ql \&%T , 225.Ql \&%u , 226.Ql \&%V , 227and 228.Ql \&%v 229conversion specifications are extensions. 230.Pp 231Use of the ISO 8601 conversions may produce non-intuitive results. 232Week 01 of a year is per definition the first week which has the Thursday 233in this year, which is equivalent to the week which contains the fourth 234day of January. 235In other words, the first week of a new year is the week which has the 236majority of its days in the new year. 237Week 01 might also contain days from the previous year and the week 238before week 01 of a year is the last week (52 or 53) of the previous 239year even if it contains days from the new year. 240A week starts with Monday (day 1) and ends with Sunday (day 7). 241For example, the first week of the year 1997 lasts from 2421996-12-30 to 1997-01-05. 243.Sh BUGS 244There is no conversion specification for the phase of the moon. 245