newstrftime.3 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. .\" strftime man page
  2. .\"
  3. .\" Based on the UCB file whose corrected copyright information appears below.
  4. .\" Copyright 1989, 1991 The Regents of the University of California.
  5. .\" All rights reserved.
  6. .\"
  7. .\" This code is derived from software contributed to Berkeley by
  8. .\" the American National Standards Committee X3, on Information
  9. .\" Processing Systems.
  10. .\"
  11. .\" Redistribution and use in source and binary forms, with or without
  12. .\" modification, are permitted provided that the following conditions
  13. .\" are met:
  14. .\" 1. Redistributions of source code must retain the above copyright
  15. .\" notice, this list of conditions and the following disclaimer.
  16. .\" 2. Redistributions in binary form must reproduce the above copyright
  17. .\" notice, this list of conditions and the following disclaimer in the
  18. .\" documentation and/or other materials provided with the distribution.
  19. .\" 3. Neither the name of the University nor the names of its contributors
  20. .\" may be used to endorse or promote products derived from this software
  21. .\" without specific prior written permission.
  22. .\"
  23. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
  24. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. .\" SUCH DAMAGE.
  34. .\"
  35. .\" from: @(#)strftime.3 5.12 (Berkeley) 6/29/91
  36. .\" $Id: strftime.3,v 1.4 1993/12/15 20:33:00 jtc Exp $
  37. .\"
  38. .TH newstrftime 3 "" "Time Zone Database"
  39. .SH NAME
  40. strftime \- format date and time
  41. .SH SYNOPSIS
  42. .nf
  43. .ie \n(.g .ds - \f(CR-\fP
  44. .el .ds - \-
  45. .B #include <time.h>
  46. .PP
  47. .B "size_t strftime(char *restrict buf, size_t maxsize,"
  48. .B " char const *restrict format, struct tm const *restrict timeptr);"
  49. .PP
  50. .B cc ... \-ltz
  51. .fi
  52. .SH DESCRIPTION
  53. .ie '\(lq'' .ds lq \&"\"
  54. .el .ds lq \(lq\"
  55. .ie '\(rq'' .ds rq \&"\"
  56. .el .ds rq \(rq\"
  57. .de c
  58. .ie \n(.g \f(CR\\$1\fP\\$2
  59. .el \\$1\\$2
  60. ..
  61. .de q
  62. \\$3\*(lq\\$1\*(rq\\$2
  63. ..
  64. The
  65. .B strftime
  66. function formats the information from
  67. .I timeptr
  68. into the array pointed to by
  69. .I buf
  70. according to the string pointed to by
  71. .IR format .
  72. .PP
  73. The
  74. .I format
  75. string consists of zero or more conversion specifications and
  76. ordinary characters.
  77. All ordinary characters are copied directly into the array.
  78. A conversion specification consists of a percent sign
  79. .Ql %
  80. and one other character.
  81. .PP
  82. No more than
  83. .I maxsize
  84. bytes are placed into the array.
  85. .PP
  86. Each conversion specification is replaced by the characters as
  87. follows which are then copied into the array.
  88. .TP
  89. %A
  90. is replaced by the locale's full weekday name.
  91. .TP
  92. %a
  93. is replaced by the locale's abbreviated weekday name.
  94. .TP
  95. %B
  96. is replaced by the locale's full month name.
  97. .TP
  98. %b or %h
  99. is replaced by the locale's abbreviated month name.
  100. .TP
  101. %C
  102. is replaced by the century (a year divided by 100 and truncated to an integer)
  103. as a decimal number [00,99].
  104. .TP
  105. %c
  106. is replaced by the locale's appropriate date and time representation.
  107. .TP
  108. %D
  109. is equivalent to
  110. .c %m/%d/%y .
  111. .TP
  112. %d
  113. is replaced by the day of the month as a decimal number [01,31].
  114. .TP
  115. %e
  116. is replaced by the day of month as a decimal number [1,31];
  117. single digits are preceded by a blank.
  118. .TP
  119. %F
  120. is equivalent to
  121. .c %Y-%m-%d
  122. (the ISO 8601 date format).
  123. .TP
  124. %G
  125. is replaced by the ISO 8601 year with century as a decimal number.
  126. See also the
  127. .c %V
  128. conversion specification.
  129. .TP
  130. %g
  131. is replaced by the ISO 8601 year without century as a decimal number [00,99].
  132. This is the year that includes the greater part of the week.
  133. (Monday as the first day of a week).
  134. See also the
  135. .c %V
  136. conversion specification.
  137. .TP
  138. %H
  139. is replaced by the hour (24-hour clock) as a decimal number [00,23].
  140. .TP
  141. %I
  142. is replaced by the hour (12-hour clock) as a decimal number [01,12].
  143. .TP
  144. %j
  145. is replaced by the day of the year as a decimal number [001,366].
  146. .TP
  147. %k
  148. is replaced by the hour (24-hour clock) as a decimal number [0,23];
  149. single digits are preceded by a blank.
  150. .TP
  151. %l
  152. is replaced by the hour (12-hour clock) as a decimal number [1,12];
  153. single digits are preceded by a blank.
  154. .TP
  155. %M
  156. is replaced by the minute as a decimal number [00,59].
  157. .TP
  158. %m
  159. is replaced by the month as a decimal number [01,12].
  160. .TP
  161. %n
  162. is replaced by a newline.
  163. .TP
  164. %p
  165. is replaced by the locale's equivalent of either
  166. .q AM
  167. or
  168. .q PM .
  169. .TP
  170. %R
  171. is replaced by the time in the format
  172. .c %H:%M .
  173. .TP
  174. %r
  175. is replaced by the locale's representation of 12-hour clock time
  176. using AM/PM notation.
  177. .TP
  178. %S
  179. is replaced by the second as a decimal number [00,60].
  180. The range of
  181. seconds is [00,60] instead of [00,59] to allow for the periodic occurrence
  182. of leap seconds.
  183. .TP
  184. %s
  185. is replaced by the number of seconds since the Epoch (see
  186. .BR ctime (3)).
  187. .TP
  188. %T
  189. is replaced by the time in the format
  190. .c %H:%M:%S .
  191. .TP
  192. %t
  193. is replaced by a tab.
  194. .TP
  195. %U
  196. is replaced by the week number of the year (Sunday as the first day of
  197. the week) as a decimal number [00,53].
  198. .TP
  199. %u
  200. is replaced by the weekday (Monday as the first day of the week)
  201. as a decimal number [1,7].
  202. .TP
  203. %V
  204. is replaced by the week number of the year (Monday as the first day of
  205. the week) as a decimal number [01,53]. If the week containing January
  206. 1 has four or more days in the new year, then it is week 1; otherwise
  207. it is week 53 of the previous year, and the next week is week 1.
  208. The year is given by the
  209. .c %G
  210. conversion specification.
  211. .TP
  212. %W
  213. is replaced by the week number of the year (Monday as the first day of
  214. the week) as a decimal number [00,53].
  215. .TP
  216. %w
  217. is replaced by the weekday (Sunday as the first day of the week)
  218. as a decimal number [0,6].
  219. .TP
  220. %X
  221. is replaced by the locale's appropriate time representation.
  222. .TP
  223. %x
  224. is replaced by the locale's appropriate date representation.
  225. .TP
  226. %Y
  227. is replaced by the year with century as a decimal number.
  228. .TP
  229. %y
  230. is replaced by the year without century as a decimal number [00,99].
  231. .TP
  232. %Z
  233. is replaced by the time zone abbreviation,
  234. or by the empty string if this is not determinable.
  235. .TP
  236. %z
  237. is replaced by the offset from the Prime Meridian
  238. in the format +HHMM or \*-HHMM (ISO 8601) as appropriate,
  239. with positive values representing locations east of Greenwich,
  240. or by the empty string if this is not determinable.
  241. The numeric time zone abbreviation \*-0000 is used when the time is
  242. Universal Time
  243. but local time is indeterminate; by convention this is used for
  244. locations while uninhabited, and corresponds to a zero offset when the
  245. time zone abbreviation begins with
  246. .q "\*-" .
  247. .TP
  248. %%
  249. is replaced by a single %.
  250. .TP
  251. %+
  252. is replaced by the locale's date and time in
  253. .BR date (1)
  254. format.
  255. .SH "RETURN VALUE"
  256. If the conversion is successful,
  257. .B strftime
  258. returns the number of bytes placed into the array, not counting the
  259. terminating NUL;
  260. .B errno
  261. is unchanged if the returned value is zero.
  262. Otherwise,
  263. .B errno
  264. is set to indicate the error, zero is returned,
  265. and the array contents are unspecified.
  266. .SH ERRORS
  267. This function fails if:
  268. .TP
  269. [ERANGE]
  270. The total number of resulting bytes, including the terminating
  271. NUL character, is more than
  272. .IR maxsize .
  273. .PP
  274. This function may fail if:
  275. .TP
  276. [EOVERFLOW]
  277. The format includes an
  278. .c %s
  279. conversion and the number of seconds since the Epoch cannot be represented
  280. in a
  281. .c time_t .
  282. .SH SEE ALSO
  283. date(1),
  284. getenv(3),
  285. newctime(3),
  286. newtzset(3),
  287. time(2),
  288. tzfile(5)
  289. .SH BUGS
  290. There is no conversion specification for the phase of the moon.