aboutsummaryrefslogtreecommitdiffstats
path: root/missing/strftime.3
blob: e6b270c8f2e6e20e8d8f1b5fdea8f6503fbaecd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
STRFTIME(3)                          Library Functions Manual                         STRFTIME(3)

NAME
       strftime - generate formatted time information

SYNOPSIS
       #include <sys/types.h>
       #include <time.h>

       size_t strftime(char *s, size_t maxsize, const char *format,
            const struct tm *timeptr);

DESCRIPTION
       The following description is transcribed verbatim from the December 7, 1988 draft standard
       for ANSI C.  This draft is essentially identical in technical content to the final version
       of the standard.

       The  strftime  function  places characters into the array pointed to by s as controlled by
       the string pointed to by format.  The format shall be a multibyte character sequence,  be-
       ginning and ending in its initial shift state.  The format string consists of zero or more
       conversion specifiers and ordinary multibyte characters.  A conversion specifier  consists
       of  a  %  character followed by a character that determines the behavior of the conversion
       specifier.  All ordinary multibyte characters (including the terminating  null  character)
       are  copied unchanged into the array.  If copying takes place between objects that overlap
       the behavior is undefined.  No more than maxsize characters are  placed  into  the  array.
       Each  conversion  specifier is replaced by appropriate characters as described in the fol-
       lowing list.  The appropriate characters are determined by the  LC_TIME  category  of  the
       current locale and by the values contained in the structure pointed to by timeptr.

       %a     is replaced by the locale's abbreviated weekday name.

       %A     is replaced by the locale's full weekday name.

       %b     is replaced by the locale's abbreviated month name.

       %B     is replaced by the locale's full month name.

       %c     is replaced by the locale's appropriate date and time representation.

       %d     is replaced by the day of the month as a decimal number (01-31).

       %H     is replaced by the hour (24-hour clock) as a decimal number (00-23).

       %I     is replaced by the hour (12-hour clock) as a decimal number (01-12).

       %j     is replaced by the day of the year as a decimal number (001-366).

       %m     is replaced by the month as a decimal number (01-12).

       %M     is replaced by the minute as a decimal number (00-59).

       %p     is  replaced by the locale's equivalent of the AM/PM designations associated with a
              12-hour clock.

       %S     is replaced by the second as a decimal number (00-60).

       %U     is replaced by the week number of the year (the first Sunday as the  first  day  of
              week 1) as a decimal number (00-53).

       %w     is replaced by the weekday as a decimal number [0 (Sunday)-6].

       %W     is  replaced  by  the week number of the year (the first Monday as the first day of
              week 1) as a decimal number (00-53).

       %x     is replaced by the locale's appropriate date representation.

       %X     is replaced by the locale's appropriate time representation.

       %y     is replaced by the year without century as a decimal number (00-99).

       %Y     is replaced by the year with century as a decimal number.

       %Z     is replaced by the time zone name or abbreviation, or by no characters if  no  time
              zone is determinable.

       %%     is replaced by %.

       If a conversion specifier is not one of the above, the behavior is undefined.

RETURNS
       If  the  total  number of resulting characters including the terminating null character is
       not more than maxsize, the strftime function returns the number of characters placed  into
       the  array  pointed to by s not including the terminating null character.  Otherwise, zero
       is returned and the contents of the array are indeterminate.

NON-ANSI EXTENSIONS
       If SYSV_EXT is defined when the routine is compiled, then the following additional conver-
       sions  will  be available.  These are borrowed from the System V cftime(3) and ascftime(3)
       routines.

       %D     is equivalent to specifying %m/%d/%y.

       %e     is replaced by the day of the month, padded with a blank if it is only one digit.

       %h     is equivalent to %b, above.

       %n     is replaced with a newline character (ASCII LF).

       %r     is equivalent to specifying %I:%M:%S %p.

       %R     is equivalent to specifying %H:%M.

       %T     is equivalent to specifying %H:%M:%S.

       %t     is replaced with a TAB character.

       If SUNOS_EXT is defined when the routine is compiled, then the following  additional  con-
       versions will be available.  These are borrowed from the SunOS version of strftime.

       %k     is  replaced  by the hour (24-hour clock) as a decimal number (0-23).  Single digit
              numbers are padded with a blank.

       %l     is replaced by the hour (12-hour clock) as a decimal number (1-12).   Single  digit
              numbers are padded with a blank.

POSIX 1003.2 EXTENSIONS
       If  POSIX2_DATE  is  defined,  then  all  of  the  conversions available with SYSV_EXT and
       SUNOS_EXT are available, as well as the following additional conversions:

       %C     The century, as a number between 00 and 99.

       %u     is replaced by the weekday as a decimal number [1 (Monday)-7].

       %V     is replaced by the week number of the year (the first Monday as the  first  day  of
              week 1) as a decimal number (01-53).  The method for determining the week number is
              as specified by ISO 8601 (to wit: if the week containing January 1 has four or more
              days  in the new year, then it is week 1, otherwise it is the highest numbered week
              of the previous year (52 or 53) and the next week is week 1).

       The text of the POSIX standard for the date utility describes %U and %W this way:

       %U     is replaced by the week number of the year (the first Sunday as the  first  day  of
              week  1)  as  a decimal number (00-53).  All days in a new year preceding the first
              Sunday are considered to be in week 0.

       %W     is replaced by the week number of the year (the first Monday as the  first  day  of
              week  1)  as  a decimal number (00-53).  All days in a new year preceding the first
              Monday are considered to be in week 0.

       In addition, the alternate representations %Ec, %EC, %Ex, %Ey, %EY, %Od,  %Oe,  %OH,  %OI,
       %Om, %OM, %OS, %Ou, %OU, %OV, %Ow, %OW, and %Oy are recognized, but their normal represen-
       tations are used.

VMS EXTENSIONS
       If VMS_EXT is defined, then the following additional conversion is available:

       %v     The date in VMS format (e.g. 20-JUN-1991).

MAIL HEADER EXTENSIONS
       If MAILHEADER_EXT is defined, then the following additional conversion is available:

       %z     The timezone offset in a  +HHMM  format  (e.g.  the  format  necessary  to  produce
              RFC-822/RFC-1036 date headers).

ISO DATE FORMAT EXTENSIONS
       If  ISO_DATE_EXT  is  defined,  then  all  of  the conversions available with POSIX2_DATE,
       SYSV_EXT, and SUNOS_EXT are available, as well as the following additional conversions:

       %G     is replaced by the year with century of the ISO week number (see %V,  above)  as  a
              decimal number.

       %g     is replaced by the year without century of the ISO week number, as a decimal number
              (00-99).

       For example, January 1, 1993, is in week 53 of 1992. Thus, the year of its ISO week number
       is  1992,  even  though  its  year is 1993.  Similarly, December 31, 1973, is in week 1 of
       1974. Thus, the year of its ISO week number is 1974, even though its year is 1973.

SEE ALSO
       time(2), ctime(3), localtime(3), tzset(3)

BUGS
       This version does not handle multibyte characters or pay attention to the setting  of  the
       LC_TIME environment variable.

       The ``appropriate'' values used for %c, %x, are %X are those specified by the 1003.2 stan-
       dard for the POSIX locale.

CAVEATS
       The pre-processor symbol POSIX_SEMANTICS is automatically defined, which forces  the  code
       to  call  tzset(3) whenever the TZ environment variable has changed.  If this routine will
       be used in an application that will not be changing TZ, then there may be some performance
       improvements by not defining POSIX_SEMANTICS.

AUTHOR
       Arnold Robbins

       INTERNET: arnold@gnu.org

ACKNOWLEDGEMENTS
       Thanks to Geoff Clare <gwc@root.co.uk> for helping debug earlier versions of this routine,
       and  for  advice  about  POSIX  semantics.   Additional  thanks  to  Arthur  David   Olsen
       <ado@elsie.nci.nih.gov>  for  some  code  improvements.   Thanks  also  to  Tor  Lillqvist
       <tml@tik.vtt.fi> for code fixes to the ISO 8601 code.  Thanks to Hume Smith  for  pointing
       out a problem with the ISO 8601 code and to Arthur David Olsen for further discussions.

                                                                                      STRFTIME(3)