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.\" $OpenBSD: strftime.3,v 1.23 2009/09/09 06:38:25 jmc Exp $ 34.\" 35.Dd $Mdocdate: September 9 2009 $ 36.Dt STRFTIME 3 37.Os 38.Sh NAME 39.Nm strftime 40.Nd format date and time 41.Sh SYNOPSIS 42.Fd #include <time.h> 43.Ft size_t 44.Fn strftime "char *buf" "size_t maxsize" "const char *format" "const struct tm *timeptr" 45.Sh DESCRIPTION 46The 47.Fn strftime 48function formats the information from 49.Fa timeptr 50into the buffer 51.Fa buf 52according to the string pointed to by 53.Fa format . 54.Pp 55The 56.Fa format 57string consists of zero or more conversion specifications and 58ordinary characters. 59All ordinary characters are copied directly into the buffer. 60A conversion specification consists of a percent sign 61.Ql % 62and one other character. 63.Pp 64No more than 65.Fa maxsize 66characters will be placed into the array. 67If the total number of resulting characters, including the terminating 68NUL character, is not more than 69.Fa maxsize , 70.Fn strftime 71returns the number of characters in the array, not counting the 72terminating NUL. 73Otherwise, zero is returned. 74.Pp 75Each conversion specification is replaced by the characters as 76follows which are then copied into the buffer. 77.Bl -tag -width "xxxx" 78.It Cm \&%A 79is replaced by the locale's full weekday name. 80.It Cm \&%a 81is replaced by the locale's abbreviated weekday name. 82.It Cm \&%B 83is replaced by the locale's full month name. 84.It Cm \&%b No or Cm \&%h 85is replaced by the locale's abbreviated month name. 86.It Cm \&%C 87is replaced by the century (a year divided by 100 and truncated to an integer) 88as a decimal number (00\-99). 89.It Cm \&%c 90is replaced by the locale's appropriate date and time representation. 91.It Cm \&%D 92is replaced by the date in the format 93.Dq Li %m/%d/%y . 94.It Cm \&%d 95is replaced by the day of the month as a decimal number (01\-31). 96.It Cm \&%e 97is replaced by the day of month as a decimal number (1\-31); 98single digits are preceded by a blank. 99.It Cm \&%F 100is replaced by the date in the format 101.Dq Li %Y-%m-%d . 102.It Cm \&%G 103is replaced by the ISO 8601 year with century as a decimal number. 104.It Cm \&%g 105is replaced by the ISO 8601 year without century as a decimal number (00\-99). 106.It Cm \&%H 107is replaced by the hour (24-hour clock) as a decimal number (00\-23). 108.It Cm \&%I 109is replaced by the hour (12-hour clock) as a decimal number (01\-12). 110.It Cm \&%j 111is replaced by the day of the year as a decimal number (001\-366). 112.It Cm \&%k 113is replaced by the hour (24-hour clock) as a decimal number (0\-23); 114single digits are preceded by a blank. 115.It Cm \&%l 116is replaced by the hour (12-hour clock) as a decimal number (1\-12); 117single digits are preceded by a blank. 118.It Cm \&%M 119is replaced by the minute as a decimal number (00\-59). 120.It Cm %m 121is replaced by the month as a decimal number (01\-12). 122.It Cm %n 123is replaced by a newline. 124.It Cm %p 125is replaced by the locale's equivalent of either 126.Dq Tn AM 127or 128.Dq Tn PM . 129.It Cm \&%R 130is replaced by the time in the format 131.Dq Li %H:%M . 132.It Cm \&%r 133is replaced by the locale's representation of 12-hour clock time 134using AM/PM notation. 135.It Cm \&%S 136is replaced by the second as a decimal number (00\-61). 137The range of 138seconds is (00\-61) instead of (00\-59) to allow for the periodic occurrence 139of leap seconds and double leap seconds. 140.It Cm %s 141is replaced by the number of seconds since the Epoch, UTC (see 142.Xr mktime 3 ) . 143.It Cm \&%T 144is replaced by the time in the format 145.Dq Li %H:%M:%S . 146.It Cm \&%t 147is replaced by a tab. 148.It Cm \&%U 149is replaced by the week number of the year (Sunday as the first day of 150the week) as a decimal number (00\-53). 151.It Cm \&%u 152is replaced by the weekday (Monday as the first day of the week) 153as a decimal number (1\-7). 154.It Cm \&%V 155is replaced by the week number of the year (Monday as the first day of 156the week) as a decimal number (01\-53). 157If the week containing January 1581 has four or more days in the new year, then it is week 1; otherwise 159it is week 53 of the previous year, and the next week is week 1. 160.It Cm \&%v 161is replaced by the date in the format 162.Dq Li "%e-%b-%Y" . 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 , 216.Ql \&%l , 217.Ql \&%s , 218.Ql \&%v , 219and 220.Ql \&%+ 221conversion specifications are extensions. 222.Pp 223Use of the ISO 8601 conversions may produce non-intuitive results. 224Week 01 of a year is per definition the first week which has the Thursday 225in this year, which is equivalent to the week which contains the fourth 226day of January. 227In other words, the first week of a new year is the week which has the 228majority of its days in the new year. 229Week 01 might also contain days from the previous year and the week 230before week 01 of a year is the last week (52 or 53) of the previous 231year even if it contains days from the new year. 232A week starts with Monday (day 1) and ends with Sunday (day 7). 233For example, the first week of the year 1997 lasts from 2341996-12-30 to 1997-01-05. 235.Sh BUGS 236There is no conversion specification for the phase of the moon. 237.Pp 238Note that while this implementation of 239.Fn strftime 240will always NUL terminate 241.Fa buf , 242other implementations may not do so when 243.Fa maxsize 244is not large enough to store the entire time string. 245The contents of 246.Fa buf 247are implementation specific in this case. 248.\" @(#)newstrftime.3 8.1 249