1strftime(3C)             Standard C Library Functions             strftime(3C)
2
3
4

NAME

6       strftime, cftime, ascftime - convert date and time to string
7

SYNOPSIS

9       #include <time.h>
10
11       size_t strftime(char *restrict s, size_t maxsize,
12            const char *restrict format,
13            const struct tm *restrict timeptr);
14
15
16       int cftime(char *s, char *format, const time_t *clock);
17
18
19       int ascftime(char *s, const char *format,
20            const struct tm *timeptr);
21
22

DESCRIPTION

24       The strftime(), ascftime(), and cftime() functions place bytes into the
25       array pointed to by s as controlled by the string pointed to by format.
26       The  format  string  consists of zero or more conversion specifications
27       and ordinary characters.  A conversion specification consists of a  '%'
28       (percent)  character  and  one or two terminating conversion characters
29       that determine the conversion specification's behavior.   All  ordinary
30       characters  (including  the terminating null byte) are copied unchanged
31       into the array pointed to by s. If copying takes place between  objects
32       that  overlap,  the behavior is undefined. For strftime(), no more than
33       maxsize bytes are placed into the array.
34
35
36       If format is (char *)0, then the locale's default format is  used.  For
37       strftime() the default format is the same as %c; for cftime() and ascf‐
38       time() the default format is the same as %C.  cftime()  and  ascftime()
39       first  try  to use the value of the environment variable CFTIME, and if
40       that is undefined or empty, the default format is used.
41
42
43       Each conversion specification is replaced by appropriate characters  as
44       described  in the following list. The appropriate characters are deter‐
45       mined by the LC_TIME category of the program's locale and by the values
46       contained  in  the  structure  pointed to by timeptr for strftime() and
47       ascftime(), and by the time represented by clock for cftime().
48
49       %%    Same as %.
50
51
52       %a    Locale's abbreviated weekday name.
53
54
55       %A    Locale's full weekday name.
56
57
58       %b    Locale's abbreviated month name.
59
60
61       %B    Locale's full month name.
62
63
64   Default
65       %c    Locale's appropriate date and time represented as:
66
67               %a %b %d %H:%M:%S %Y
68
69             This is the  default  behavior  as  well  as  standard-conforming
70             behavior  for  standards  first  supported  by  releases prior to
71             Solaris 2.4. See standards(5).
72
73
74   Standard conforming
75       %c    Locale's appropriate date and time represented as:
76
77               %a %b %e %H:%M:%S %Y
78
79             This is standard-conforming behavior  for  standards  first  sup‐
80             ported by Solaris 2.4 through Solaris 10.
81
82
83   Default
84       %C    Locale's date and time representation as produced by date(1).
85
86             This  is  the  default  behavior  as  well as standard-conforming
87             behavior for standards  first  supported  by  releases  prior  to
88             Solaris 2.4.
89
90
91   Standard conforming
92       %C    Century number (the year divided by 100 and truncated to an inte‐
93             ger as a decimal number [01,99]).
94
95             This is standard-conforming behavior  for  standards  first  sup‐
96             ported by Solaris 2.4 through Solaris 10.
97
98
99       %d    Day of month [01,31].
100
101
102       %D    Date as %m/%d/%y.
103
104
105       %e    Day of month [1,31]; single  digits are preceded by a space.
106
107
108       %F    Equivalent to %Y-%m-%d (the ISO 8601:2000 standard date format).
109
110
111       %g    Week-based year within century [00,99].
112
113
114       %G    Week-based year, including the century [0000,9999].
115
116
117       %h    Locale's abbreviated month name.
118
119
120       %H    Hour (24-hour clock) [00,23].
121
122
123       %I    Hour (12-hour clock) [01,12].
124
125
126       %j    Day number of year [001,366].
127
128
129       %k    Hour  (24-hour  clock)  [0,23];  single  digits are preceded by a
130             space.
131
132
133       %l    Hour (12-hour clock) [1,12]; single  digits  are  preceded  by  a
134             space.
135
136
137       %m    Month number [01,12].
138
139
140       %M    Minute [00,59].
141
142
143       %n    Insert a NEWLINE.
144
145
146       %p    Locale's equivalent of either a.m. or p.m.
147
148
149       %r    Appropriate time representation in 12-hour clock format with %p.
150
151
152       %R    Time as %H:%M.
153
154
155       %S    Seconds  [00,60];  the  range  of  values  is [00,60] rather than
156             [00,59] to allow for the occasional leap second.
157
158
159       %t    Insert a TAB.
160
161
162       %T    Time as %H:%M:%S.
163
164
165       %u    Weekday as a decimal number [1,7], with  1  representing  Monday.
166             See NOTES below.
167
168
169       %U    Week  number  of year as a decimal number [00,53], with Sunday as
170             the first day of week 1.
171
172
173       %V    The ISO 8601 week number as a decimal number [01,53]. In the  ISO
174             8601 week-based system, weeks begin on a Monday and week 1 of the
175             year is the week that includes both January  4th  and  the  first
176             Thursday of the year.  If the first Monday of January is the 2nd,
177             3rd, or 4th, the preceding days are part of the last week of  the
178             preceding year.  See NOTES below.
179
180
181       %w    Weekday as a decimal number [0,6], with 0 representing Sunday.
182
183
184       %W    Week  number  of year as a decimal number [00,53], with Monday as
185             the first day of week 1.
186
187
188       %x    Locale's appropriate date representation.
189
190
191       %X    Locale's appropriate time representation.
192
193
194       %y    Year within century [00,99].
195
196
197       %Y    Year, including the century (for example 1993).
198
199
200       %z    Replaced by offset from UTC  in  ISO  8601:2000  standard  format
201             (+hhmm  or  -hhmm), or by no characters if no time zone is deter‐
202             minable. For example, "-0430" means 4 hours 30 minutes behind UTC
203             (west  of Greenwich). If tm_isdst is zero, the standard time off‐
204             set is used.  If tm_isdst is greater than zero, the daylight sav‐
205             ings  time offset if used. If tm_isdst is negative, no characters
206             are returned.
207
208
209       %Z    Time zone name or abbreviation, or  no  bytes  if  no  time  zone
210             information exists.
211
212
213
214       If  a  conversion specification does not correspond to any of the above
215       or to any of the modified conversion specifications listed  below,  the
216       behavior is undefined and 0 is returned.
217
218
219       The  difference between %U and %W (and also between modified conversion
220       specifications %OU and %OW) lies in which day is counted as  the  first
221       of the week. Week number 1 is the first week in January starting with a
222       Sunday for %U or a Monday for %W. Week number  0  contains  those  days
223       before  the  first  Sunday  or Monday in January for %U and %W, respec‐
224       tively.
225
226   Modified Conversion Specifications
227       Some conversion specifications can be modified by the E and O modifiers
228       to  indicate  that  an alternate format or specification should be used
229       rather than the one normally used by the unmodified conversion specifi‐
230       cation.  If the alternate format or specification does not exist in the
231       current locale, the behavior will be as if the unmodified specification
232       were used.
233
234       %Ec    Locale's alternate appropriate date and time representation.
235
236
237       %EC    Name  of the base year (period) in the locale's alternate repre‐
238              sentation.
239
240
241       %Eg    Offset from %EC of the week-based year in the locale's  alterna‐
242              tive representation.
243
244
245       %EG    Full alternative representation of the week-based year.
246
247
248       %Ex    Locale's alternate date representation.
249
250
251       %EX    Locale's alternate time representation.
252
253
254       %Ey    Offset  from %EC (year only) in the locale's alternate represen‐
255              tation.
256
257
258       %EY    Full alternate year representation.
259
260
261       %Od    Day of the month using the locale's alternate numeric symbols.
262
263
264       %Oe    Same as %Od.
265
266
267       %Og    Week-based year (offset from %C) in the locale's alternate  rep‐
268              resentation and using the locale's alternate numeric symbols.
269
270
271       %OH    Hour  (24-hour  clock) using the locale's alternate numeric sym‐
272              bols.
273
274
275       %OI    Hour (12-hour clock) using the locale's alternate  numeric  sym‐
276              bols.
277
278
279       %Om    Month using the locale's alternate numeric symbols.
280
281
282       %OM    Minutes using the locale's alternate numeric symbols.
283
284
285       %OS    Seconds using the locale's alternate numeric symbols.
286
287
288       %Ou    Weekday as a number in the locale's alternate numeric symbols.
289
290
291       %OU    Week  number  of  the year (Sunday as the first day of the week)
292              using the locale's alternate numeric symbols.
293
294
295       %Ow    Number of the weekday (Sunday=0) using the   locale's  alternate
296              numeric symbols.
297
298
299       %OW    Week  number  of  the year (Monday as the first day of the week)
300              using the locale's alternate numeric symbols.
301
302
303       %Oy    Year (offset from %C) in the locale's  alternate  representation
304              and using the locale's alternate numeric symbols.
305
306
307   Selecting the Output Language
308       By  default,  the output of strftime(), cftime(), and ascftime() appear
309       in U.S. English. The user can request that the  output  of  strftime(),
310       cftime(),  or  ascftime()  be  in  a  specific  language by setting the
311       LC_TIME category using setlocale().
312
313   Time Zone
314       Local time zone information is used as though tzset(3C) were called.
315

RETURN VALUES

317       The strftime(), cftime(), and ascftime() functions return the number of
318       characters  placed  into  the  array pointed to by s, not including the
319       terminating null character. If the total number of resulting characters
320       including  the  terminating  null character is more than maxsize, strf‐
321       time() returns 0 and the contents of the array are indeterminate.
322

EXAMPLES

324       Example 1 An example of the strftime() function.
325
326
327       The following example illustrates the use of strftime() for  the  POSIX
328       locale.  It  shows what the string in str would look like if the struc‐
329       ture pointed to by tmptr contains the values corresponding to Thursday,
330       August 28, 1986 at 12:44:36.
331
332
333         strftime (str, strsize, "%A %b %d %j", tmptr)
334
335
336
337       This results in str containing "Thursday Aug 28 240".
338
339

ATTRIBUTES

341       See attributes(5) for descriptions of the following attributes:
342
343
344
345
346       ┌─────────────────────────────┬─────────────────────────────┐
347       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
348       ├─────────────────────────────┼─────────────────────────────┤
349       │CSI                          │Enabled                      │
350       ├─────────────────────────────┼─────────────────────────────┤
351       │Interface Stability          │Committed                    │
352       ├─────────────────────────────┼─────────────────────────────┤
353       │MT-Level                     │MT-Safe                      │
354       ├─────────────────────────────┼─────────────────────────────┤
355       │Standard                     │See below.                   │
356       └─────────────────────────────┴─────────────────────────────┘
357
358
359       For strftime(), see standards(5).
360

SEE ALSO

362       date(1), ctime(3C), mktime(3C), setlocale(3C), strptime(3C), tzset(3C),
363       TIMEZONE(4), zoneinfo(4), attributes(5), environ(5), standards(5)
364

NOTES

366       The conversion specification for  %V  was  changed  in  the  Solaris  7
367       release.  This  change  was based on the public review draft of the ISO
368       C9x standard at that time. Previously, the specification stated that if
369       the week containing 1 January had fewer than four days in the new year,
370       it became week 53 of the previous year. The ISO C9x standard  committee
371       subsequently recognized that that specification had been incorrect.
372
373
374       The  conversion specifications for %g, %G, %Eg, %EG, and %Og were added
375       in the Solaris 7 release.  This change was based on the  public  review
376       draft  of  the  ISO C9x standard at that time. These specifications are
377       evolving.  If the ISO C9x standard is finalized with a  different  con‐
378       clusion,  these  specifications  will  change to conform to the ISO C9x
379       standard decision.
380
381
382       The conversion specification for  %u  was  changed  in  the  Solaris  8
383       release. This change was based on the XPG4 specification.
384
385
386       If  using the %Z specifier and zoneinfo timezones and if the input date
387       is outside the range 20:45:52 UTC, December  13, 1901 to 03:14:07  UTC,
388       January 19, 2038, the timezone name may not be correct.
389
390
391
392SunOS 5.11                        5 Sep 2006                      strftime(3C)
Impressum