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.30 2013/09/20 19:06:54 christos Exp $ 34.\" 35.Dd April 14, 2011 36.Dt STRFTIME 3 37.Os 38.Sh NAME 39.Nm strftime , 40.Nm strftime_z 41.Nd format date and time 42.Sh LIBRARY 43.Lb libc 44.Sh SYNOPSIS 45.In time.h 46.Ft size_t 47.Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr" 48.Ft size_t 49.Fn strftime_z "const timezone_t tz" "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr" 50.Sh DESCRIPTION 51The 52.Fn strftime 53function formats the information from 54.Fa timeptr 55into the buffer 56.Fa buf 57according to the string pointed to by 58.Fa format . 59.Pp 60The 61.Fa format 62string consists of zero or more conversion specifications and 63ordinary characters. 64All ordinary characters are copied directly into the buffer. 65A conversion specification consists of a percent sign 66.Ql % 67and one other character. 68.Pp 69No more than 70.Fa maxsize 71characters will be placed into the array. 72If the total number of resulting characters, including the terminating 73null character, is not more than 74.Fa maxsize , 75.Fn strftime 76returns the number of characters in the array, not counting the 77terminating null. 78Otherwise, zero is returned and the contents of the array are undefined. 79.Pp 80Each conversion specification is replaced by the characters as 81follows which are then copied into the buffer. 82.Bl -tag -width "xxxx" 83.It Cm \&%A 84is replaced by the locale's full weekday name. 85.It Cm %a 86is replaced by the locale's abbreviated weekday name. 87.It Cm \&%B 88is replaced by the locale's full month name. 89.It Cm \&%b No or Cm \&%h 90is replaced by the locale's abbreviated month name. 91.It Cm \&%C 92is replaced by the century (a year divided by 100 and truncated to an integer) 93as a decimal number [00,99]. 94.It Cm \&%c 95is replaced by the locale's appropriate date and time representation. 96.It Cm \&%D 97is replaced by the date in the format 98.Dq Li %m/%d/%y . 99.It Cm \&%d 100is replaced by the day of the month as a decimal number [01,31]. 101.It Cm \&%e 102is replaced by the day of month as a decimal number [1,31]; 103single digits are preceded by a blank. 104.It Cm \&%F 105is replaced by the date in the format 106.Dq Li %Y-%m-%d 107(the ISO 8601 date format). 108.It Cm \&%G 109is replaced by the ISO 8601 year with century as a decimal number. 110.It Cm \&%g 111is replaced by the ISO 8601 year without century as a decimal number (00-99). 112This is the year that includes the greater part of the week. 113(Monday as the first day of a week). 114See also the 115.Ql \&%V 116conversion specification. 117.It Cm \&%H 118is replaced by the hour (24-hour clock) as a decimal number [00,23]. 119.It Cm \&%I 120is replaced by the hour (12-hour clock) as a decimal number [01,12]. 121.It Cm \&%j 122is replaced by the day of the year as a decimal number [001,366]. 123.It Cm \&%k 124is replaced by the hour (24-hour clock) as a decimal number [0,23]; 125single digits are preceded by a blank. 126.It Cm \&%l 127is replaced by the hour (12-hour clock) as a decimal number [1,12]; 128single digits are preceded by a blank. 129.It Cm \&%M 130is replaced by the minute as a decimal number [00,59]. 131.It Cm %m 132is replaced by the month as a decimal number [01,12]. 133.It Cm %n 134is replaced by a newline. 135.It Cm %p 136is replaced by the locale's equivalent of either 137.Dq Tn AM 138or 139.Dq Tn PM . 140.It Cm \&%R 141is replaced by the time in the format 142.Dq Li %H:%M . 143.It Cm \&%r 144is replaced by the locale's representation of 12-hour clock time 145using AM/PM notation. 146.It Cm \&%S 147is replaced by the second as a decimal number [00,61]. 148The range of 149seconds is (00-61) instead of (00-59) to allow for the periodic occurrence 150of leap seconds and double leap seconds. 151.It Cm %s 152is replaced by the number of seconds since the Epoch (see 153.Xr ctime 3 ) . 154.It Cm \&%T 155is replaced by the time in the format 156.Dq Li %H:%M:%S . 157.It Cm \&%t 158is replaced by a tab. 159.It Cm \&%U 160is replaced by the week number of the year (Sunday as the first day of 161the week) as a decimal number [00,53]. 162.It Cm \&%u 163is replaced by the weekday (Monday as the first day of the week) 164as a decimal number [1,7]. 165.It Cm \&%V 166is replaced by the week number of the year (Monday as the first day of 167the week) as a decimal number [01,53]. According to ISO 8601 the week 168containing January 1 is week 1 if it has four or more days in the new year, 169otherwise it is week 53 of the previous year, and the next week is week 1. 170The year is given by the 171.Ql \&%G 172conversion specification. 173.It Cm \&%v 174is replaced by the date in the format 175.Dq Li %e-%b-%Y . 176.It Cm \&%W 177is replaced by the week number of the year (Monday as the first day of 178the week) as a decimal number [00,53]. 179.It Cm \&%w 180is replaced by the weekday (Sunday as the first day of the week) 181as a decimal number [0,6]. 182.It Cm \&%X 183is replaced by the locale's appropriate time representation. 184.It Cm \&%x 185is replaced by the locale's appropriate date representation. 186.It Cm \&%Y 187is replaced by the year with century as a decimal number. 188.It Cm \&%y 189is replaced by the year without century as a decimal number [00,99]. 190.It Cm \&%Z 191is replaced by the time zone name. 192.It Cm \&%z 193is replaced by the offset from the Prime Meridian in the format 194+HHMM or -HHMM (ISO 8601) as appropriate, with positive values representing 195locations east of Greenwich, or by the empty string if this is 196not determinable. 197.Dq Li [-]hhmm . 198.It Cm %% 199is replaced by 200.Ql % . 201.El 202.Pp 203The 204.Fn strftime_z 205function is similar to 206.Fn strftime , 207but it also takes a 208.Ft "const timezone_t" 209.Fa tz 210argument. 211.Sh SEE ALSO 212.Xr date 1 , 213.Xr printf 1 , 214.Xr ctime 3 , 215.Xr printf 3 , 216.Xr strptime 3 , 217.Xr tm 3 218.Sh STANDARDS 219The 220.Fn strftime 221function 222conforms to 223.St -isoC-99 . 224The 225.Ql \&%C , 226.Ql \&%D , 227.Ql \&%e , 228.Ql \&%g , 229.Ql \&%G , 230.Ql \&%h , 231.Ql \&%k , 232.Ql \&%l , 233.Ql \&%n , 234.Ql \&%r , 235.Ql \&%R , 236.Ql \&%s , 237.Ql \&%t , 238.Ql \&%T , 239.Ql \&%u , 240.Ql \&%V , 241and 242.Ql \&%v 243conversion specifications are extensions. 244.Pp 245Use of the ISO 8601 conversions may produce non-intuitive results. 246Week 01 of a year is per definition the first week which has the Thursday 247in this year, which is equivalent to the week which contains the fourth 248day of January. 249In other words, the first week of a new year is the week which has the 250majority of its days in the new year. 251Week 01 might also contain days from the previous year and the week 252before week 01 of a year is the last week (52 or 53) of the previous 253year even if it contains days from the new year. 254A week starts with Monday (day 1) and ends with Sunday (day 7). 255For example, the first week of the year 1997 lasts from 2561996-12-30 to 1997-01-05. 257.Sh BUGS 258There is no conversion specification for the phase of the moon. 259.Pp 260A return value of zero does not necessarily indicate an error. 261If the resulting string is an empty string, the result value is 262zero and it is not possible to distinguish between success and error. 263For example, in many locales 264.Cm \&%p 265yields an empty string. 266This problem can be avoided by inserting an extra space at the 267beginning of the format string and then skipping over it or removing 268it from the result. 269