xref: /minix3/lib/libc/time/strftime.3 (revision 84d9c625bfea59e274550651111ae9edfdc40fbd)
12fe8fb19SBen Gras.\" Copyright (c) 1989, 1991 The Regents of the University of California.
22fe8fb19SBen Gras.\" All rights reserved.
32fe8fb19SBen Gras.\"
42fe8fb19SBen Gras.\" This code is derived from software contributed to Berkeley by
52fe8fb19SBen Gras.\" the American National Standards Committee X3, on Information
62fe8fb19SBen Gras.\" Processing Systems.
72fe8fb19SBen Gras.\"
82fe8fb19SBen Gras.\" Redistribution and use in source and binary forms, with or without
92fe8fb19SBen Gras.\" modification, are permitted provided that the following conditions
102fe8fb19SBen Gras.\" are met:
112fe8fb19SBen Gras.\" 1. Redistributions of source code must retain the above copyright
122fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer.
132fe8fb19SBen Gras.\" 2. Redistributions in binary form must reproduce the above copyright
142fe8fb19SBen Gras.\"    notice, this list of conditions and the following disclaimer in the
152fe8fb19SBen Gras.\"    documentation and/or other materials provided with the distribution.
162fe8fb19SBen Gras.\" 3. Neither the name of the University nor the names of its contributors
172fe8fb19SBen Gras.\"    may be used to endorse or promote products derived from this software
182fe8fb19SBen Gras.\"    without specific prior written permission.
192fe8fb19SBen Gras.\"
202fe8fb19SBen Gras.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
212fe8fb19SBen Gras.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
222fe8fb19SBen Gras.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
232fe8fb19SBen Gras.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
242fe8fb19SBen Gras.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
252fe8fb19SBen Gras.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
262fe8fb19SBen Gras.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
272fe8fb19SBen Gras.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
282fe8fb19SBen Gras.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
292fe8fb19SBen Gras.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
302fe8fb19SBen Gras.\" SUCH DAMAGE.
312fe8fb19SBen Gras.\"
322fe8fb19SBen Gras.\"     from: @(#)strftime.3	5.12 (Berkeley) 6/29/91
33*84d9c625SLionel Sambuc.\"	$NetBSD: strftime.3,v 1.30 2013/09/20 19:06:54 christos Exp $
342fe8fb19SBen Gras.\"
35f14fb602SLionel Sambuc.Dd April 14, 2011
362fe8fb19SBen Gras.Dt STRFTIME 3
372fe8fb19SBen Gras.Os
382fe8fb19SBen Gras.Sh NAME
392fe8fb19SBen Gras.Nm strftime ,
402fe8fb19SBen Gras.Nm strftime_z
412fe8fb19SBen Gras.Nd format date and time
422fe8fb19SBen Gras.Sh LIBRARY
432fe8fb19SBen Gras.Lb libc
442fe8fb19SBen Gras.Sh SYNOPSIS
452fe8fb19SBen Gras.In time.h
462fe8fb19SBen Gras.Ft size_t
472fe8fb19SBen Gras.Fn strftime "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
482fe8fb19SBen Gras.Ft size_t
492fe8fb19SBen Gras.Fn strftime_z "const timezone_t tz" "char * restrict buf" "size_t maxsize" "const char * restrict format" "const struct tm * restrict timeptr"
502fe8fb19SBen Gras.Sh DESCRIPTION
512fe8fb19SBen GrasThe
522fe8fb19SBen Gras.Fn strftime
532fe8fb19SBen Grasfunction formats the information from
542fe8fb19SBen Gras.Fa timeptr
552fe8fb19SBen Grasinto the buffer
562fe8fb19SBen Gras.Fa buf
572fe8fb19SBen Grasaccording to the string pointed to by
582fe8fb19SBen Gras.Fa format .
592fe8fb19SBen Gras.Pp
602fe8fb19SBen GrasThe
612fe8fb19SBen Gras.Fa format
622fe8fb19SBen Grasstring consists of zero or more conversion specifications and
632fe8fb19SBen Grasordinary characters.
642fe8fb19SBen GrasAll ordinary characters are copied directly into the buffer.
652fe8fb19SBen GrasA conversion specification consists of a percent sign
662fe8fb19SBen Gras.Ql %
672fe8fb19SBen Grasand one other character.
682fe8fb19SBen Gras.Pp
692fe8fb19SBen GrasNo more than
702fe8fb19SBen Gras.Fa maxsize
712fe8fb19SBen Grascharacters will be placed into the array.
722fe8fb19SBen GrasIf the total number of resulting characters, including the terminating
732fe8fb19SBen Grasnull character, is not more than
742fe8fb19SBen Gras.Fa maxsize ,
752fe8fb19SBen Gras.Fn strftime
762fe8fb19SBen Grasreturns the number of characters in the array, not counting the
772fe8fb19SBen Grasterminating null.
782fe8fb19SBen GrasOtherwise, zero is returned and the contents of the array are undefined.
792fe8fb19SBen Gras.Pp
802fe8fb19SBen GrasEach conversion specification is replaced by the characters as
812fe8fb19SBen Grasfollows which are then copied into the buffer.
822fe8fb19SBen Gras.Bl -tag -width "xxxx"
832fe8fb19SBen Gras.It Cm \&%A
842fe8fb19SBen Grasis replaced by the locale's full weekday name.
852fe8fb19SBen Gras.It Cm %a
862fe8fb19SBen Grasis replaced by the locale's abbreviated weekday name.
872fe8fb19SBen Gras.It Cm \&%B
882fe8fb19SBen Grasis replaced by the locale's full month name.
892fe8fb19SBen Gras.It Cm \&%b No or Cm \&%h
902fe8fb19SBen Grasis replaced by the locale's abbreviated month name.
912fe8fb19SBen Gras.It Cm \&%C
922fe8fb19SBen Grasis replaced by the century (a year divided by 100 and truncated to an integer)
932fe8fb19SBen Grasas a decimal number [00,99].
942fe8fb19SBen Gras.It Cm \&%c
952fe8fb19SBen Grasis replaced by the locale's appropriate date and time representation.
962fe8fb19SBen Gras.It Cm \&%D
972fe8fb19SBen Grasis replaced by the date in the format
982fe8fb19SBen Gras.Dq Li %m/%d/%y .
992fe8fb19SBen Gras.It Cm \&%d
1002fe8fb19SBen Grasis replaced by the day of the month as a decimal number [01,31].
1012fe8fb19SBen Gras.It Cm \&%e
1022fe8fb19SBen Grasis replaced by the day of month as a decimal number [1,31];
1032fe8fb19SBen Grassingle digits are preceded by a blank.
1042fe8fb19SBen Gras.It Cm \&%F
1052fe8fb19SBen Grasis replaced by the date in the format
1062fe8fb19SBen Gras.Dq Li %Y-%m-%d
1072fe8fb19SBen Gras(the ISO 8601 date format).
1082fe8fb19SBen Gras.It Cm \&%G
1092fe8fb19SBen Grasis replaced by the ISO 8601 year with century as a decimal number.
1102fe8fb19SBen Gras.It Cm \&%g
1112fe8fb19SBen Grasis replaced by the ISO 8601 year without century as a decimal number (00-99).
1122fe8fb19SBen GrasThis is the year that includes the greater part of the week.
1132fe8fb19SBen Gras(Monday as the first day of a week).
1142fe8fb19SBen GrasSee also the
1152fe8fb19SBen Gras.Ql \&%V
1162fe8fb19SBen Grasconversion specification.
1172fe8fb19SBen Gras.It Cm \&%H
1182fe8fb19SBen Grasis replaced by the hour (24-hour clock) as a decimal number [00,23].
1192fe8fb19SBen Gras.It Cm \&%I
1202fe8fb19SBen Grasis replaced by the hour (12-hour clock) as a decimal number [01,12].
1212fe8fb19SBen Gras.It Cm \&%j
1222fe8fb19SBen Grasis replaced by the day of the year as a decimal number [001,366].
1232fe8fb19SBen Gras.It Cm \&%k
1242fe8fb19SBen Grasis replaced by the hour (24-hour clock) as a decimal number [0,23];
1252fe8fb19SBen Grassingle digits are preceded by a blank.
1262fe8fb19SBen Gras.It Cm \&%l
1272fe8fb19SBen Grasis replaced by the hour (12-hour clock) as a decimal number [1,12];
1282fe8fb19SBen Grassingle digits are preceded by a blank.
1292fe8fb19SBen Gras.It Cm \&%M
1302fe8fb19SBen Grasis replaced by the minute as a decimal number [00,59].
1312fe8fb19SBen Gras.It Cm %m
1322fe8fb19SBen Grasis replaced by the month as a decimal number [01,12].
1332fe8fb19SBen Gras.It Cm %n
1342fe8fb19SBen Grasis replaced by a newline.
1352fe8fb19SBen Gras.It Cm %p
1362fe8fb19SBen Grasis replaced by the locale's equivalent of either
1372fe8fb19SBen Gras.Dq Tn AM
1382fe8fb19SBen Grasor
1392fe8fb19SBen Gras.Dq Tn PM .
1402fe8fb19SBen Gras.It Cm \&%R
1412fe8fb19SBen Grasis replaced by the time in the format
1422fe8fb19SBen Gras.Dq Li %H:%M .
1432fe8fb19SBen Gras.It Cm \&%r
1442fe8fb19SBen Grasis replaced by the locale's representation of 12-hour clock time
1452fe8fb19SBen Grasusing AM/PM notation.
1462fe8fb19SBen Gras.It Cm \&%S
1472fe8fb19SBen Grasis replaced by the second as a decimal number [00,61].
1482fe8fb19SBen GrasThe range of
1492fe8fb19SBen Grasseconds is (00-61) instead of (00-59) to allow for the periodic occurrence
1502fe8fb19SBen Grasof leap seconds and double leap seconds.
1512fe8fb19SBen Gras.It Cm %s
152*84d9c625SLionel Sambucis replaced by the number of seconds since the Epoch (see
153*84d9c625SLionel Sambuc.Xr ctime 3 ) .
1542fe8fb19SBen Gras.It Cm \&%T
1552fe8fb19SBen Grasis replaced by the time in the format
1562fe8fb19SBen Gras.Dq Li %H:%M:%S .
1572fe8fb19SBen Gras.It Cm \&%t
1582fe8fb19SBen Grasis replaced by a tab.
1592fe8fb19SBen Gras.It Cm \&%U
1602fe8fb19SBen Grasis replaced by the week number of the year (Sunday as the first day of
1612fe8fb19SBen Grasthe week) as a decimal number [00,53].
1622fe8fb19SBen Gras.It Cm \&%u
1632fe8fb19SBen Grasis replaced by the weekday (Monday as the first day of the week)
1642fe8fb19SBen Grasas a decimal number [1,7].
1652fe8fb19SBen Gras.It Cm \&%V
1662fe8fb19SBen Grasis replaced by the week number of the year (Monday as the first day of
1672fe8fb19SBen Grasthe week) as a decimal number [01,53]. According to ISO 8601 the week
1682fe8fb19SBen Grascontaining January 1 is week 1 if it has four or more days in the new year,
1692fe8fb19SBen Grasotherwise it is week 53 of the previous year, and the next week is week 1.
1702fe8fb19SBen GrasThe year is given by the
1712fe8fb19SBen Gras.Ql \&%G
1722fe8fb19SBen Grasconversion specification.
1732fe8fb19SBen Gras.It Cm \&%v
1742fe8fb19SBen Grasis replaced by the date in the format
1752fe8fb19SBen Gras.Dq Li %e-%b-%Y .
1762fe8fb19SBen Gras.It Cm \&%W
1772fe8fb19SBen Grasis replaced by the week number of the year (Monday as the first day of
1782fe8fb19SBen Grasthe week) as a decimal number [00,53].
1792fe8fb19SBen Gras.It Cm \&%w
1802fe8fb19SBen Grasis replaced by the weekday (Sunday as the first day of the week)
1812fe8fb19SBen Grasas a decimal number [0,6].
1822fe8fb19SBen Gras.It Cm \&%X
1832fe8fb19SBen Grasis replaced by the locale's appropriate time representation.
1842fe8fb19SBen Gras.It Cm \&%x
1852fe8fb19SBen Grasis replaced by the locale's appropriate date representation.
1862fe8fb19SBen Gras.It Cm \&%Y
1872fe8fb19SBen Grasis replaced by the year with century as a decimal number.
1882fe8fb19SBen Gras.It Cm \&%y
1892fe8fb19SBen Grasis replaced by the year without century as a decimal number [00,99].
1902fe8fb19SBen Gras.It Cm \&%Z
1912fe8fb19SBen Grasis replaced by the time zone name.
1922fe8fb19SBen Gras.It Cm \&%z
193*84d9c625SLionel Sambucis replaced by the offset from the Prime Meridian in the format
194*84d9c625SLionel Sambuc+HHMM or -HHMM (ISO 8601) as appropriate, with positive values representing
195*84d9c625SLionel Sambuclocations east of Greenwich, or by the empty string if this is
196*84d9c625SLionel Sambucnot determinable.
1972fe8fb19SBen Gras.Dq Li [-]hhmm .
1982fe8fb19SBen Gras.It Cm %%
1992fe8fb19SBen Grasis replaced by
2002fe8fb19SBen Gras.Ql % .
2012fe8fb19SBen Gras.El
2022fe8fb19SBen Gras.Pp
2032fe8fb19SBen GrasThe
2042fe8fb19SBen Gras.Fn strftime_z
2052fe8fb19SBen Grasfunction is similar to
2062fe8fb19SBen Gras.Fn strftime ,
2072fe8fb19SBen Grasbut it also takes a
2082fe8fb19SBen Gras.Ft "const timezone_t"
2092fe8fb19SBen Gras.Fa tz
2102fe8fb19SBen Grasargument.
2112fe8fb19SBen Gras.Sh SEE ALSO
2122fe8fb19SBen Gras.Xr date 1 ,
2132fe8fb19SBen Gras.Xr printf 1 ,
2142fe8fb19SBen Gras.Xr ctime 3 ,
2152fe8fb19SBen Gras.Xr printf 3 ,
216f14fb602SLionel Sambuc.Xr strptime 3 ,
217f14fb602SLionel Sambuc.Xr tm 3
2182fe8fb19SBen Gras.Sh STANDARDS
2192fe8fb19SBen GrasThe
2202fe8fb19SBen Gras.Fn strftime
2212fe8fb19SBen Grasfunction
2222fe8fb19SBen Grasconforms to
2232fe8fb19SBen Gras.St -isoC-99 .
2242fe8fb19SBen GrasThe
2252fe8fb19SBen Gras.Ql \&%C ,
2262fe8fb19SBen Gras.Ql \&%D ,
2272fe8fb19SBen Gras.Ql \&%e ,
2282fe8fb19SBen Gras.Ql \&%g ,
2292fe8fb19SBen Gras.Ql \&%G ,
2302fe8fb19SBen Gras.Ql \&%h ,
2312fe8fb19SBen Gras.Ql \&%k ,
2322fe8fb19SBen Gras.Ql \&%l ,
2332fe8fb19SBen Gras.Ql \&%n ,
2342fe8fb19SBen Gras.Ql \&%r ,
2352fe8fb19SBen Gras.Ql \&%R ,
2362fe8fb19SBen Gras.Ql \&%s ,
2372fe8fb19SBen Gras.Ql \&%t ,
2382fe8fb19SBen Gras.Ql \&%T ,
2392fe8fb19SBen Gras.Ql \&%u ,
2402fe8fb19SBen Gras.Ql \&%V ,
2412fe8fb19SBen Grasand
2422fe8fb19SBen Gras.Ql \&%v
2432fe8fb19SBen Grasconversion specifications are extensions.
2442fe8fb19SBen Gras.Pp
2452fe8fb19SBen GrasUse of the ISO 8601 conversions may produce non-intuitive results.
2462fe8fb19SBen GrasWeek 01 of a year is per definition the first week which has the Thursday
2472fe8fb19SBen Grasin this year, which is equivalent to the week which contains the fourth
2482fe8fb19SBen Grasday of January.
2492fe8fb19SBen GrasIn other words, the first week of a new year is the week which has the
2502fe8fb19SBen Grasmajority of its days in the new year.
2512fe8fb19SBen GrasWeek 01 might also contain days from the previous year and the week
2522fe8fb19SBen Grasbefore week 01 of a year is the last week (52 or 53) of the previous
2532fe8fb19SBen Grasyear even if it contains days from the new year.
2542fe8fb19SBen GrasA week starts with Monday (day 1) and ends with Sunday (day 7).
2552fe8fb19SBen GrasFor example, the first week of the year 1997 lasts from
2562fe8fb19SBen Gras1996-12-30 to 1997-01-05.
2572fe8fb19SBen Gras.Sh BUGS
2582fe8fb19SBen GrasThere is no conversion specification for the phase of the moon.
2592fe8fb19SBen Gras.Pp
2602fe8fb19SBen GrasA return value of zero does not necessarily indicate an error.
2612fe8fb19SBen GrasIf the resulting string is an empty string, the result value is
2622fe8fb19SBen Graszero and it is not possible to distinguish between success and error.
2632fe8fb19SBen GrasFor example, in many locales
2642fe8fb19SBen Gras.Cm \&%p
2652fe8fb19SBen Grasyields an empty string.
2662fe8fb19SBen GrasThis problem can be avoided by inserting an extra space at the
2672fe8fb19SBen Grasbeginning of the format string and then skipping over it or removing
2682fe8fb19SBen Grasit from the result.
269