1 .\" Copyright (c) 1989, 1991 The Regents of the University of California.
2 .\" All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" the American National Standards Committee X3, on Information
6 .\" Processing Systems.
8 .\" Redistribution and use in source and binary forms, with or without
9 .\" modification, are permitted provided that the following conditions
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.
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
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 $
41 .Nd format date and time
47 .Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
49 .Fn strftime_z "const timezone_t tz" "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
53 function formats the information from
57 according to the string pointed to by
62 string consists of zero or more conversion specifications and
64 All ordinary characters are copied directly into the buffer.
65 A conversion specification consists of a percent sign
67 and one other character.
71 characters will be placed into the array.
72 If the total number of resulting characters, including the terminating
73 null character, is not more than
76 returns the number of characters in the array, not counting the
78 Otherwise, zero is returned and the contents of the array are undefined.
80 Each conversion specification is replaced by the characters as
81 follows which are then copied into the buffer.
82 .Bl -tag -width "xxxx"
84 is replaced by the locale's full weekday name.
86 is replaced by the locale's abbreviated weekday name.
88 is replaced by the locale's full month name.
89 .It Cm \&%b No or Cm \&%h
90 is replaced by the locale's abbreviated month name.
92 is replaced by the century (a year divided by 100 and truncated to an integer)
93 as a decimal number [00,99].
95 is replaced by the locale's appropriate date and time representation.
97 is replaced by the date in the format
100 is replaced by the day of the month as a decimal number [01,31].
102 is replaced by the day of month as a decimal number [1,31];
103 single digits are preceded by a blank.
105 is replaced by the date in the format
107 (the ISO 8601 date format).
109 is replaced by the ISO 8601 year with century as a decimal number.
111 is replaced by the ISO 8601 year without century as a decimal number (00-99).
112 This is the year that includes the greater part of the week.
113 (Monday as the first day of a week).
116 conversion specification.
118 is replaced by the hour (24-hour clock) as a decimal number [00,23].
120 is replaced by the hour (12-hour clock) as a decimal number [01,12].
122 is replaced by the day of the year as a decimal number [001,366].
124 is replaced by the hour (24-hour clock) as a decimal number [0,23];
125 single digits are preceded by a blank.
127 is replaced by the hour (12-hour clock) as a decimal number [1,12];
128 single digits are preceded by a blank.
130 is replaced by the minute as a decimal number [00,59].
132 is replaced by the month as a decimal number [01,12].
134 is replaced by a newline.
136 is replaced by the locale's equivalent of either
141 is replaced by the time in the format
144 is replaced by the locale's representation of 12-hour clock time
145 using AM/PM notation.
147 is replaced by the second as a decimal number [00,61].
149 seconds is (00-61) instead of (00-59) to allow for the periodic occurrence
150 of leap seconds and double leap seconds.
152 is replaced by the number of seconds since the Epoch (see
155 is replaced by the time in the format
158 is replaced by a tab.
160 is replaced by the week number of the year (Sunday as the first day of
161 the week) as a decimal number [00,53].
163 is replaced by the weekday (Monday as the first day of the week)
164 as a decimal number [1,7].
166 is replaced by the week number of the year (Monday as the first day of
167 the week) as a decimal number [01,53]. According to ISO 8601 the week
168 containing January 1 is week 1 if it has four or more days in the new year,
169 otherwise it is week 53 of the previous year, and the next week is week 1.
170 The year is given by the
172 conversion specification.
174 is replaced by the date in the format
177 is replaced by the week number of the year (Monday as the first day of
178 the week) as a decimal number [00,53].
180 is replaced by the weekday (Sunday as the first day of the week)
181 as a decimal number [0,6].
183 is replaced by the locale's appropriate time representation.
185 is replaced by the locale's appropriate date representation.
187 is replaced by the year with century as a decimal number.
189 is replaced by the year without century as a decimal number [00,99].
191 is replaced by the time zone name.
193 is replaced by the offset from the Prime Meridian in the format
194 +HHMM or -HHMM (ISO 8601) as appropriate, with positive values representing
195 locations east of Greenwich, or by the empty string if this is
205 function is similar to
208 .Ft "const timezone_t"
243 conversion specifications are extensions.
245 Use of the ISO 8601 conversions may produce non-intuitive results.
246 Week 01 of a year is per definition the first week which has the Thursday
247 in this year, which is equivalent to the week which contains the fourth
249 In other words, the first week of a new year is the week which has the
250 majority of its days in the new year.
251 Week 01 might also contain days from the previous year and the week
252 before week 01 of a year is the last week (52 or 53) of the previous
253 year even if it contains days from the new year.
254 A week starts with Monday (day 1) and ends with Sunday (day 7).
255 For example, the first week of the year 1997 lasts from
256 1996-12-30 to 1997-01-05.
258 There is no conversion specification for the phase of the moon.
260 A return value of zero does not necessarily indicate an error.
261 If the resulting string is an empty string, the result value is
262 zero and it is not possible to distinguish between success and error.
263 For example, in many locales
265 yields an empty string.
266 This problem can be avoided by inserting an extra space at the
267 beginning of the format string and then skipping over it or removing