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.36 2016/02/08 20:29:11 jmc Exp $ 34.\" 35.Dd $Mdocdate: February 8 2016 $ 36.Dt STRFTIME 3 37.Os 38.Sh NAME 39.Nm strftime 40.Nd format date and time 41.Sh SYNOPSIS 42.In 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 50(as described in 51.Xr mktime 3 ) 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. 69.Pp 70Each conversion specification is replaced by the characters as 71follows which are then copied into the buffer. 72.Bl -tag -width "xxxx" 73.It Cm \&%A 74is replaced by the locale's full weekday name. 75.It Cm \&%a 76is replaced by the locale's abbreviated weekday name. 77.It Cm \&%B 78is replaced by the locale's full month name. 79.It Cm \&%b No or Cm \&%h 80is replaced by the locale's abbreviated month name. 81.It Cm \&%C 82is replaced by the century (a year divided by 100 and truncated to an integer) 83as a decimal number (00\-99). 84.It Cm \&%c 85is replaced by the locale's appropriate date and time representation. 86.It Cm \&%D 87is replaced by the date in the format 88.Dq Li %m/%d/%y . 89.It Cm \&%d 90is replaced by the day of the month as a decimal number (01\-31). 91.It Cm \&%e 92is replaced by the day of month as a decimal number (1\-31); 93single digits are preceded by a blank. 94.It Cm \&%F 95is replaced by the date in the format 96.Dq Li %Y-%m-%d . 97.It Cm \&%G 98is replaced by the 99.St -iso8601 100year with century as a decimal number. 101.It Cm \&%g 102is replaced by the 103.St -iso8601 104year without century as a decimal number (00\-99). 105.It Cm \&%H 106is replaced by the hour (24-hour clock) as a decimal number (00\-23). 107.It Cm \&%I 108is replaced by the hour (12-hour clock) as a decimal number (01\-12). 109.It Cm \&%j 110is replaced by the day of the year as a decimal number (001\-366). 111.It Cm \&%k 112is replaced by the hour (24-hour clock) as a decimal number (0\-23); 113single digits are preceded by a blank. 114.It Cm \&%l 115is replaced by the hour (12-hour clock) as a decimal number (1\-12); 116single digits are preceded by a blank. 117.It Cm \&%M 118is replaced by the minute as a decimal number (00\-59). 119.It Cm %m 120is replaced by the month as a decimal number (01\-12). 121.It Cm %n 122is replaced by a newline. 123.It Cm %p 124is replaced by the locale's equivalent of either 125.Dq AM 126or 127.Dq PM . 128.It Cm \&%R 129is replaced by the time in the format 130.Dq Li %H:%M . 131.It Cm \&%r 132is replaced by the locale's representation of 12-hour clock time 133using AM/PM notation. 134.It Cm \&%S 135is replaced by the second as a decimal number (00\-60). 136The range of 137seconds is (00\-60) instead of (00\-59) to allow for the periodic occurrence 138of leap seconds. 139.It Cm %s 140is replaced by the number of seconds since the Epoch, UTC (see 141.Xr mktime 3 ) . 142.It Cm \&%T 143is replaced by the time in the format 144.Dq Li %H:%M:%S . 145.It Cm \&%t 146is replaced by a tab. 147.It Cm \&%U 148is replaced by the week number of the year (Sunday as the first day of 149the week) as a decimal number (00\-53). 150.It Cm \&%u 151is replaced by the weekday (Monday as the first day of the week) 152as a decimal number (1\-7). 153.It Cm \&%V 154is replaced by the week number of the year (Monday as the first day of 155the week) as a decimal number (01\-53). 156If the week containing January 1571 has four or more days in the new year, then it is week 1; otherwise 158it is week 53 of the previous year, and the next week is week 1. 159.It Cm \&%v 160is replaced by the date in the format 161.Dq Li "%e-%b-%Y" . 162.It Cm \&%W 163is replaced by the week number of the year (Monday as the first day of 164the week) as a decimal number (00\-53). 165.It Cm \&%w 166is replaced by the weekday (Sunday as the first day of the week) 167as a decimal number (0\-6). 168.It Cm \&%X 169is replaced by the locale's appropriate time representation. 170.It Cm \&%x 171is replaced by the locale's appropriate date representation. 172.It Cm \&%Y 173is replaced by the year with century as a decimal number. 174.It Cm \&%y 175is replaced by the year without century as a decimal number (00\-99). 176.It Cm \&%Z 177is replaced by the time zone name, 178or by the empty string if this is not determinable. 179.It Cm \&%z 180is replaced by the offset from UTC in the format 181.Dq Li +HHMM 182or 183.Dq Li -HHMM 184as appropriate, with positive values representing locations east 185of Greenwich, or by the empty string if this is not determinable. 186.It Cm %% 187is replaced by 188.Ql % . 189.It Cm %+ 190is replaced by the date and time in 191.Xr date 1 192format. 193.El 194.Sh RETURN VALUES 195If the total number of resulting characters, including the terminating 196NUL character, is not more than 197.Fa maxsize , 198.Fn strftime 199returns the number of characters placed in the array, not counting the 200terminating NUL. 201Otherwise, zero is returned. 202.Sh SEE ALSO 203.Xr date 1 , 204.Xr printf 1 , 205.Xr ctime 3 , 206.Xr getenv 3 , 207.Xr printf 3 , 208.Xr strptime 3 , 209.Xr time 3 , 210.Xr tzset 3 , 211.Xr tzfile 5 212.Sh STANDARDS 213The 214.Fn strftime 215function 216conforms to 217.St -isoC-99 , 218except that the 219.Ql E 220and 221.Ql O 222conversion modifiers are ignored by this implementation. 223.Pp 224The 225.Ql \&%k , 226.Ql \&%l , 227.Ql \&%s , 228.Ql \&%v , 229and 230.Ql \&%+ 231conversion specifications are extensions. 232.Pp 233Use of the 234.St -iso8601 235conversions may produce non-intuitive results. 236Week 01 of a year is per definition the first week which has the Thursday 237in this year, which is equivalent to the week which contains the fourth 238day of January. 239In other words, the first week of a new year is the week which has the 240majority of its days in the new year. 241Week 01 might also contain days from the previous year and the week 242before week 01 of a year is the last week (52 or 53) of the previous 243year even if it contains days from the new year. 244A week starts with Monday (day 1) and ends with Sunday (day 7). 245For example, the first week of the year 1997 lasts from 2461996-12-30 to 1997-01-05. 247.Sh HISTORY 248A predecessor to 249.Fn strftime , 250.Fn ptime , 251first appeared in 252.At v1 . 253The 254.Fn strftime 255function has been available since 256.Bx 4.3 Reno . 257.Sh AUTHORS 258.An Keith Bostic 259implemented the 260.Bx 261version of 262.Fn strftime 263in 1989. 264.Sh BUGS 265There is no conversion specification for the phase of the moon. 266.Pp 267Note that while this implementation of 268.Fn strftime 269will always NUL terminate 270.Fa buf , 271other implementations may not do so when 272.Fa maxsize 273is not large enough to store the entire time string. 274The contents of 275.Fa buf 276are implementation specific in this case. 277