8999 SMBIOS: cleanup 32-bit specific code
[unleashed.git] / usr / src / man / man3c / strftime.3c
blob83e1fce77ac2d4dd8e9461cbc39adaacb84151ed
1 '\" te
2 .\" Copyright 2014 Garrett D'Amore <garrett@damore.org>
3 .\" Copyright (c) 2014 Gary Mills
4 .\" Copyright (c) 2008, Sun Microsystems, Inc.  All Rights Reserved.
5 .\" Copyright 1989 AT&T
6 .\" Portions Copyright (c) 1992, X/Open Company Limited.  All Rights Reserved.
7 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at
8 .\" http://www.opengroup.org/bookstore/.
9 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.
10 .\"  This notice shall appear on any product containing this material.
11 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License").  You may not use this file except in compliance with the License.
12 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing.  See the License for the specific language governing permissions and limitations under the License.
13 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE.  If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
14 .TH STRFTIME 3C "Jun 24, 2014"
15 .SH NAME
16 strftime, strftime_l cftime, ascftime \- convert date and time to string
17 .SH SYNOPSIS
18 .LP
19 .nf
20 #include <time.h>
22 \fBsize_t\fR \fBstrftime\fR(\fBchar *restrict\fR \fIs\fR, \fBsize_t\fR \fImaxsize\fR,
23      \fBconst char *restrict\fR \fIformat\fR,
24      \fBconst struct tm *restrict\fR \fItimeptr\fR);
25 .fi
26 .LP
27 .nf
28 \fBsize_t\fR \fBstrftime_l\fR(\fBchar *restrict\fR \fIs\fR, \fBsize_t\fR \fImaxsize\fR,
29      \fBconst char *restrict\fR \fIformat\fR,
30      \fBconst struct tm *restrict\fR \fItimeptr\fR, \fBlocale_t\fR \fIloc\fR);
31 .fi
32 .LP
33 .nf
34 \fBint\fR \fBcftime\fR(\fBchar *\fR\fIs\fR, \fBchar *\fR\fIformat\fR, \fBconst time_t *\fR\fIclock\fR);
35 .fi
36 .LP
37 .nf
38 \fBint\fR \fBascftime\fR(\fBchar *\fR\fIs\fR, \fBconst char *\fR\fIformat\fR,
39      \fBconst struct tm *\fR\fItimeptr\fR);
40 .fi
42 .SH DESCRIPTION
43 .sp
44 .LP
45 The \fBstrftime()\fR, \fBstrftime_l()\fR, \fBascftime()\fR, and \fBcftime()\fR
46 functions place
47 bytes into the array pointed to by \fIs\fR as controlled by the string pointed
48 to by \fIformat\fR. The \fIformat\fR string consists of zero or more conversion
49 specifications and ordinary characters.  A conversion specification consists of
50 a '\fB%\fR' (percent) character and one or two terminating conversion
51 characters that determine the conversion specification's behavior.  All
52 ordinary characters (including the terminating null byte) are copied unchanged
53 into the array pointed to by \fIs\fR. If copying takes place between objects
54 that overlap, the behavior is undefined. For \fBstrftime()\fR, no more than
55 \fImaxsize\fR bytes are placed into the array. The \fBstrftime_l()\fR function
56 behaves identically to \fBstrftime()\fR function, but instead of operating in
57 the current locale, it operates in the locale specified by \fIloc\fR.
58 .LP
59 If \fIformat\fR is \fB(char *)0\fR, then the locale's default format is used.
60 For \fBstrftime()\fR the default format is the same as \fB%c\fR; for
61 \fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%+\fR.
62 \fBcftime()\fR and \fBascftime()\fR first try to use the value of the
63 environment variable \fBCFTIME\fR, and if that is undefined or empty, the
64 default format is used.
65 .LP
66 Each conversion specification is replaced by appropriate characters as
67 described in the following list. The appropriate characters are determined by
68 the \fBLC_TIME\fR category of the program's locale and by the values contained
69 in the structure pointed to by \fItimeptr\fR for \fBstrftime()\fR and
70 \fBascftime()\fR, and by the time represented by \fIclock\fR for
71 \fBcftime()\fR.
72 .sp
73 .ne 2
74 .na
75 \fB\fB%%\fR\fR
76 .ad
77 .RS 6n
78 Same as \fB%\fR.
79 .RE
81 .sp
82 .ne 2
83 .na
84 \fB\fB%a\fR\fR
85 .ad
86 .RS 6n
87 Locale's abbreviated weekday name.
88 .RE
90 .sp
91 .ne 2
92 .na
93 \fB\fB%A\fR\fR
94 .ad
95 .RS 6n
96 Locale's full weekday name.
97 .RE
99 .sp
100 .ne 2
102 \fB\fB%b\fR\fR
104 .RS 6n
105 Locale's abbreviated month name.
109 .ne 2
111 \fB\fB%B\fR\fR
113 .RS 6n
114 Locale's full month name.
118 .ne 2
120 \fB\fB%c\fR\fR
122 .RS 6n
123 Locale's appropriate date and time representation.
124 In the C locale, this format is:
126 .in +2
128 %a %b %e %H:%M:%S %Y
130 .in -2
132 Other locales may have different locale-specific formats.
136 .ne 2
138 \fB\fB%C\fR\fR
140 .RS 6n
141 Century number (the year divided by 100 and truncated to an integer as a
142 decimal number [01,99]).
146 .ne 2
148 \fB\fB%d\fR\fR
150 .RS 6n
151 Day of month [01,31].
155 .ne 2
157 \fB\fB%D\fR\fR
159 .RS 6n
160 Date as \fB%m\fR/\fB%d\fR/\fB%y\fR.
164 .ne 2
166 \fB\fB%e\fR\fR
168 .RS 6n
169 Day of month [1,31]; single  digits are preceded by a space.
173 .ne 2
175 \fB\fB%F\fR\fR
177 .RS 6n
178 Equivalent to \fB%Y\fR-\fB%m\fR-\fB%d\fR (the ISO 8601:2000 standard date
179 format).
183 .ne 2
185 \fB\fB%g\fR\fR
187 .RS 6n
188 Week-based year within century [00,99].
192 .ne 2
194 \fB\fB%G\fR\fR
196 .RS 6n
197 Week-based year, including the century [0000,9999].
201 .ne 2
203 \fB\fB%h\fR\fR
205 .RS 6n
206 Locale's abbreviated month name.
210 .ne 2
212 \fB\fB%H\fR\fR
214 .RS 6n
215 Hour (24-hour clock) [00,23].
219 .ne 2
221 \fB\fB%I\fR\fR
223 .RS 6n
224 Hour (12-hour clock) [01,12].
228 .ne 2
230 \fB\fB%j\fR\fR
232 .RS 6n
233 Day number of year [001,366].
237 .ne 2
239 \fB\fB%k\fR\fR
241 .RS 6n
242 Hour (24-hour clock) [0,23]; single digits are preceded by a space.
246 .ne 2
248 \fB\fB%l\fR\fR
250 .RS 6n
251 Hour (12-hour clock) [1,12]; single digits are preceded by a space.
255 .ne 2
257 \fB\fB%m\fR\fR
259 .RS 6n
260 Month number [01,12].
264 .ne 2
266 \fB\fB%M\fR\fR
268 .RS 6n
269 Minute [00,59].
273 .ne 2
275 \fB\fB%n\fR\fR
277 .RS 6n
278 Insert a NEWLINE.
282 .ne 2
284 \fB\fB%p\fR\fR
286 .RS 6n
287 Locale's equivalent of either a.m. or p.m.
291 .ne 2
293 \fB\fB%r\fR\fR
295 .RS 6n
296 Appropriate time representation in 12-hour clock format with \fB%p\fR.
300 .ne 2
302 \fB\fB%R\fR\fR
304 .RS 6n
305 Time as \fB%H\fR:\fB%M\fR.
309 .ne 2
311 \fB\fB%s\fR\fR
313 .RS 6n
314 Seconds since 00:00:00 UTC, January 1, 1970.
318 .ne 2
320 \fB\fB%S\fR\fR
322 .RS 6n
323 Seconds [00,60]; the range of values is [00,60] rather than [00,59] to allow
324 for the occasional leap second.
328 .ne 2
330 \fB\fB%t\fR\fR
332 .RS 6n
333 Insert a TAB.
337 .ne 2
339 \fB\fB%T\fR\fR
341 .RS 6n
342 Time as \fB%H\fR:\fB%M\fR:\fB%S\fR.
346 .ne 2
348 \fB\fB%u\fR\fR
350 .RS 6n
351 Weekday as a decimal number [1,7], with 1 representing Monday. See \fBNOTES\fR
352 below.
356 .ne 2
358 \fB\fB%U\fR\fR
360 .RS 6n
361 Week number of year as a decimal number [00,53], with Sunday as the first day
362 of week 1.
366 .ne 2
368 \fB\fB%v\fR\fR
370 .RS 6n
371 Date as \fB%e\fR-\fB%b\fR-\fB%Y\fR.
375 .ne 2
377 \fB\fB%V\fR\fR
379 .RS 6n
380 The ISO 8601 week number as a decimal number [01,53]. In the ISO 8601
381 week-based system, weeks begin on a Monday and week 1 of the year is the week
382 that includes both January 4th and the first Thursday of the year.  If the
383 first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of
384 the last week of the preceding year.  See \fBNOTES\fR below.
388 .ne 2
390 \fB\fB%w\fR\fR
392 .RS 6n
393 Weekday as a decimal number [0,6], with 0 representing Sunday.
397 .ne 2
399 \fB\fB%W\fR\fR
401 .RS 6n
402 Week number of year as a decimal number [00,53], with Monday as the first day
403 of week 1.
407 .ne 2
409 \fB\fB%x\fR\fR
411 .RS 6n
412 Locale's appropriate date representation.
416 .ne 2
418 \fB\fB%X\fR\fR
420 .RS 6n
421 Locale's appropriate time representation.
425 .ne 2
427 \fB\fB%y\fR\fR
429 .RS 6n
430 Year within century [00,99].
434 .ne 2
436 \fB\fB%Y\fR\fR
438 .RS 6n
439 Year, including the century (for example 1993).
443 .ne 2
445 \fB\fB%z\fR\fR
447 .RS 6n
448 Replaced by offset from UTC in ISO 8601:2000 standard format (\fB+hhmm\fR or
449 \fB-hhmm\fR), or by no characters if no time zone is determinable. For example,
450 "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich). If
451 \fBtm_isdst\fR is zero, the standard time offset is used.  If \fBtm_isdst\fR is
452 greater than zero, the daylight savings time offset if used. If \fBtm_isdst\fR
453 is negative, no characters are returned.
457 .ne 2
459 \fB\fB%Z\fR\fR
461 .RS 6n
462 Time zone name or abbreviation, or no bytes if no time zone information exists.
466 .ne 2
468 \fB\fB%+\fR\fR
470 .RS 6n
471 Locale's date and time representation as produced by \fBdate\fR(1).
475 If a conversion specification does not correspond to any of the above or to any
476 of the modified conversion specifications listed below, the behavior is
477 undefined and \fB0\fR is returned.
479 The difference between \fB%U\fR and \fB%W\fR (and also between modified
480 conversion specifications \fB%OU\fR and \fB%OW\fR) lies in which day is counted
481 as the first of the week. Week number 1 is the first week in January starting
482 with a Sunday for \fB%U\fR or a Monday for \fB%W\fR. Week number 0 contains
483 those days before the first Sunday or Monday in January for \fB%U\fR and
484 \fB%W\fR, respectively.
485 .SS "Modified Conversion Specifications"
487 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
488 modifiers to indicate that an alternate format or specification should be used
489 rather than the one normally used by the unmodified conversion specification.
490 If the alternate format or specification does not exist in the current locale,
491 the behavior will be as if the unmodified specification were used.
493 .ne 2
495 \fB\fB%Ec\fR\fR
497 .RS 7n
498 Locale's alternate appropriate date and time representation.
502 .ne 2
504 \fB\fB%EC\fR\fR
506 .RS 7n
507 Name of the base year (period) in the locale's alternate representation.
511 .ne 2
513 \fB\fB%Eg\fR\fR
515 .RS 7n
516 Offset from \fB%EC\fR of the week-based year in the locale's alternative
517 representation.
521 .ne 2
523 \fB\fB%EG\fR\fR
525 .RS 7n
526 Full alternative representation of the week-based year.
530 .ne 2
532 \fB\fB%Ex\fR\fR
534 .RS 7n
535 Locale's alternate date representation.
539 .ne 2
541 \fB\fB%EX\fR\fR
543 .RS 7n
544 Locale's alternate time representation.
548 .ne 2
550 \fB\fB%Ey\fR\fR
552 .RS 7n
553 Offset from \fB%EC\fR (year only) in the locale's alternate representation.
557 .ne 2
559 \fB\fB%EY\fR\fR
561 .RS 7n
562 Full alternate year representation.
566 .ne 2
568 \fB\fB%Od\fR\fR
570 .RS 7n
571 Day of the month using the locale's alternate numeric symbols.
575 .ne 2
577 \fB\fB%Oe\fR\fR
579 .RS 7n
580 Same as \fB%Od\fR.
584 .ne 2
586 \fB\fB%Og\fR\fR
588 .RS 7n
589 Week-based year (offset from \fB%C\fR) in the locale's alternate representation
590 and using the locale's alternate numeric symbols.
594 .ne 2
596 \fB\fB%OH\fR\fR
598 .RS 7n
599 Hour (24-hour clock) using the locale's alternate numeric symbols.
603 .ne 2
605 \fB\fB%OI\fR\fR
607 .RS 7n
608 Hour (12-hour clock) using the locale's alternate numeric symbols.
612 .ne 2
614 \fB\fB%Om\fR\fR
616 .RS 7n
617 Month using the locale's alternate numeric symbols.
621 .ne 2
623 \fB\fB%OM\fR\fR
625 .RS 7n
626 Minutes using the locale's alternate numeric symbols.
630 .ne 2
632 \fB\fB%OS\fR\fR
634 .RS 7n
635 Seconds using the locale's alternate numeric symbols.
639 .ne 2
641 \fB\fB%Ou\fR\fR
643 .RS 7n
644 Weekday as a number in the locale's alternate numeric symbols.
648 .ne 2
650 \fB\fB%OU\fR\fR
652 .RS 7n
653 Week number of the year (Sunday as the first day of the week) using the
654 locale's alternate numeric symbols.
658 .ne 2
660 \fB\fB%Ow\fR\fR
662 .RS 7n
663 Number of the weekday (Sunday=0) using the  locale's alternate numeric symbols.
667 .ne 2
669 \fB\fB%OW\fR\fR
671 .RS 7n
672 Week number of the year (Monday as the first day of the week) using the
673 locale's alternate numeric symbols.
677 .ne 2
679 \fB\fB%Oy\fR\fR
681 .RS 7n
682 Year (offset from \fB%C\fR) in the locale's alternate representation and using
683 the locale's alternate numeric symbols.
686 .SS "Selecting the Output Language"
688 These routines produce output that is formatted according to the \fBLC_TIME\fR
689 locale category.  They use either the current locale, or in the case of
690 \fBstrftime_l()\fR, the locale supplied by \fIloc\fR.
691 .SS "Time Zone"
693 Local time zone information is used as though \fBtzset\fR(3C) were called.
694 .SH RETURN VALUES
696 These functions return the
697 number of characters placed into the array pointed to by \fIs\fR, not including
698 the terminating null character. If the total number of resulting characters
699 including the terminating null character is more than \fImaxsize\fR,
700 \fBstrftime()\fR returns \fB0\fR and the contents of the array are
701 indeterminate.
702 .SH EXAMPLES
704 \fBExample 1 \fRAn example of the \fBstrftime()\fR function.
706 The following example illustrates the use of \fBstrftime()\fR for the
707 \fBPOSIX\fR locale. It shows what the string in \fIstr\fR would look like if
708 the structure pointed to by \fItmptr\fR contains the values corresponding to
709 Thursday, August 28, 1986 at 12:44:36.
712 \fBstrftime\fR(\fIstr\fR, \fIstrsize\fR, "%A %b %d %j", \fItmptr\fR);
715 This results in \fIstr\fR containing "Thursday Aug 28 240".
716 .SH ATTRIBUTES
718 See \fBattributes\fR(5) for descriptions of the following attributes:
720 box;
721 c | c
722 l | l .
723 ATTRIBUTE TYPE  ATTRIBUTE VALUE
725 CSI     Enabled
727 Interface Stability     See below.
729 MT-Level        MT-Safe
731 Standard        See below.
735 The \fBstrftime()\fR and \fBstrftime_l()\fR functions are Standard.
736 \fBcftime()\fR and \fBascftime()\fR functions are Committed.
738 For \fBstrftime()\fR and \fBstrftime_l()\fR, see \fBstandards\fR(5).
739 .SH SEE ALSO
741 \fBdate\fR(1), \fBctime\fR(3C), \fBmktime\fR(3C),
742 \fBnewlocale\fR(3C), \fBsetlocale\fR(3C), \fBstrptime\fR(3C), \fBtzset\fR(3C),
743 \fBuselocale\fR(3C), \fBTIMEZONE\fR(4), \fBzoneinfo\fR(4),
744 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
745 .SH NOTES
747 The conversion specification for \fB%V\fR was changed in the Solaris 7 release.
748 This change was based on the public review draft of the ISO C9x standard at
749 that time. Previously, the specification stated that if the week containing 1
750 January had fewer than four days in the new year, it became week 53 of the
751 previous year. The ISO C9x standard committee subsequently recognized that that
752 specification had been incorrect.
754 The conversion specifications for \fB%g\fR, \fB%G\fR, \fB%Eg\fR, \fB%EG\fR, and
755 \fB%Og\fR were added in the Solaris 7 release.  This change was based on the
756 public review draft of the ISO C9x standard at that time. The \fB%g\fR and
757 \fB%G\fR specifications were adopted in the formal standard.  The other two
758 were not, and should not be used in portable applications.
760 The conversion specification for \fB%u\fR was changed in the Solaris 8 release.
761 This change was based on the XPG4 specification.
763 If using the \fB%Z\fR specifier and \fBzoneinfo\fR timezones and if the input
764 date is outside the range 20:45:52 UTC, December  13, 1901 to 03:14:07 UTC,
765 January 19, 2038, the timezone name may not be correct.
767 The conversion specification for \fB%+\fR was added in illumos.
768 It is not part of any standard, although it is available on a number
769 of other platforms.
770 Its use is discouraged for conforming applications.