1 '\" te
2 .\" Copyright (c) 2014 Gary Mills
3 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Copyright 1989 AT&T
5 .\" Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
6 .\" 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
7 .\" http://www.opengroup.org/bookstore/.
8 .\" 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.
9 .\" This notice shall appear on any product containing this material.
10 .\" 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.
11 .\" 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.
12 .\" 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]
13 .TH STRFTIME 3C "Jan 3, 2014"
14 .SH NAME
15 strftime, strftime_l cftime, ascftime \- convert date and time to string
16 .SH SYNOPSIS
17 .LP
18 .nf
19 #include <time.h>
20
21 \fBsize_t\fR \fBstrftime\fR(\fBchar *restrict\fR \fIs\fR, \fBsize_t\fR \fImaxsize\fR,
22 \fBconst char *restrict\fR \fIformat\fR,
23 \fBconst struct tm *restrict\fR \fItimeptr\fR);
24 \fBsize_t\fR \fBstrftime_l\fR(\fBchar *restrict\fR \fIs\fR, \fBsize_t\fR \fImaxsize\fR,
25 \fBconst char *restrict\fR \fIformat\fR,
26 \fBconst struct tm *restrict\fR \fItimeptr\fR, \fBlocale_t\fR \fIloc\fR);
27 .fi
28
29 .LP
30 .nf
31 \fBint\fR \fBcftime\fR(\fBchar *\fR\fIs\fR, \fBchar *\fR\fIformat\fR, \fBconst time_t *\fR\fIclock\fR);
32 .fi
33
34 .LP
35 .nf
36 \fBint\fR \fBascftime\fR(\fBchar *\fR\fIs\fR, \fBconst char *\fR\fIformat\fR,
37 \fBconst struct tm *\fR\fItimeptr\fR);
38 .fi
39
40 .SH DESCRIPTION
41 .sp
42 .LP
43 The \fBstrftime()\fR, \fBascftime()\fR, and \fBcftime()\fR functions place
44 bytes into the array pointed to by \fIs\fR as controlled by the string pointed
45 to by \fIformat\fR. The \fIformat\fR string consists of zero or more conversion
46 specifications and ordinary characters. A conversion specification consists of
47 a '\fB%\fR' (percent) character and one or two terminating conversion
48 characters that determine the conversion specification's behavior. All
49 ordinary characters (including the terminating null byte) are copied unchanged
50 into the array pointed to by \fIs\fR. If copying takes place between objects
51 that overlap, the behavior is undefined. For \fBstrftime()\fR, no more than
52 \fImaxsize\fR bytes are placed into the array. The \fBstrftime_l()\fR function
53 behaves identically to \fBstrftime()\fR function, but instead of operating in
54 the current locale, it operates in the locale specified by \fIloc\fR.
55 .sp
56 .LP
57 If \fIformat\fR is \fB(char *)0\fR, then the locale's default format is used.
58 For \fBstrftime()\fR the default format is the same as \fB%c\fR; for
59 \fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%+\fR.
60 \fBcftime()\fR and \fBascftime()\fR first try to use the value of the
61 environment variable \fBCFTIME\fR, and if that is undefined or empty, the
62 default format is used.
63 .sp
64 .LP
65 Each conversion specification is replaced by appropriate characters as
66 described in the following list. The appropriate characters are determined by
67 the \fBLC_TIME\fR category of the program's locale and by the values contained
68 in the structure pointed to by \fItimeptr\fR for \fBstrftime()\fR and
69 \fBascftime()\fR, and by the time represented by \fIclock\fR for
70 \fBcftime()\fR.
71 .sp
72 .ne 2
73 .na
74 \fB\fB%%\fR\fR
75 .ad
76 .RS 6n
77 Same as \fB%\fR.
78 .RE
79
80 .sp
81 .ne 2
82 .na
83 \fB\fB%a\fR\fR
453 .RE
454
455 .sp
456 .ne 2
457 .na
458 \fB\fB%Z\fR\fR
459 .ad
460 .RS 6n
461 Time zone name or abbreviation, or no bytes if no time zone information exists.
462 .RE
463
464 .sp
465 .ne 2
466 .na
467 \fB\fB%+\fR\fR
468 .ad
469 .RS 6n
470 Locale's date and time representation as produced by \fBdate\fR(1).
471 .RE
472
473 .sp
474 .LP
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.
478 .sp
479 .LP
480 The difference between \fB%U\fR and \fB%W\fR (and also between modified
481 conversion specifications \fB%OU\fR and \fB%OW\fR) lies in which day is counted
482 as the first of the week. Week number 1 is the first week in January starting
483 with a Sunday for \fB%U\fR or a Monday for \fB%W\fR. Week number 0 contains
484 those days before the first Sunday or Monday in January for \fB%U\fR and
485 \fB%W\fR, respectively.
486 .SS "Modified Conversion Specifications"
487 .sp
488 .LP
489 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
490 modifiers to indicate that an alternate format or specification should be used
491 rather than the one normally used by the unmodified conversion specification.
492 If the alternate format or specification does not exist in the current locale,
493 the behavior will be as if the unmodified specification were used.
494 .sp
495 .ne 2
496 .na
497 \fB\fB%Ec\fR\fR
498 .ad
499 .RS 7n
500 Locale's alternate appropriate date and time representation.
501 .RE
502
503 .sp
504 .ne 2
505 .na
506 \fB\fB%EC\fR\fR
507 .ad
669 .ne 2
670 .na
671 \fB\fB%OW\fR\fR
672 .ad
673 .RS 7n
674 Week number of the year (Monday as the first day of the week) using the
675 locale's alternate numeric symbols.
676 .RE
677
678 .sp
679 .ne 2
680 .na
681 \fB\fB%Oy\fR\fR
682 .ad
683 .RS 7n
684 Year (offset from \fB%C\fR) in the locale's alternate representation and using
685 the locale's alternate numeric symbols.
686 .RE
687
688 .SS "Selecting the Output Language"
689 .sp
690 .LP
691 By default, the output of \fBstrftime()\fR, \fBcftime()\fR, and
692 \fBascftime()\fR appear in U.S. English. The user can request that the output
693 of \fBstrftime()\fR, \fBcftime()\fR, or \fBascftime()\fR be in a specific
694 language by setting the \fBLC_TIME\fR category using \fBsetlocale()\fR.
695 .SS "Time Zone"
696 .sp
697 .LP
698 Local time zone information is used as though \fBtzset\fR(3C) were called.
699 .SH RETURN VALUES
700 .sp
701 .LP
702 The \fBstrftime()\fR, \fBcftime()\fR, and \fBascftime()\fR functions return the
703 number of characters placed into the array pointed to by \fIs\fR, not including
704 the terminating null character. If the total number of resulting characters
705 including the terminating null character is more than \fImaxsize\fR,
706 \fBstrftime()\fR returns \fB0\fR and the contents of the array are
707 indeterminate.
708 .SH EXAMPLES
709 .LP
710 \fBExample 1 \fRAn example of the \fBstrftime()\fR function.
711 .sp
712 .LP
713 The following example illustrates the use of \fBstrftime()\fR for the
714 \fBPOSIX\fR locale. It shows what the string in \fIstr\fR would look like if
715 the structure pointed to by \fItmptr\fR contains the values corresponding to
716 Thursday, August 28, 1986 at 12:44:36.
717
718 .sp
719 .in +2
720 .nf
721 \fBstrftime (str, strsize, "%A %b %d %j", tmptr)\fR
722 .fi
723 .in -2
724
725 .sp
726 .LP
727 This results in \fIstr\fR containing "Thursday Aug 28 240".
728
729 .SH ATTRIBUTES
730 .sp
731 .LP
732 See \fBattributes\fR(5) for descriptions of the following attributes:
733 .sp
734
735 .sp
736 .TS
737 box;
738 c | c
739 l | l .
740 ATTRIBUTE TYPE ATTRIBUTE VALUE
741 _
742 CSI Enabled
743 _
744 Interface Stability Committed
745 _
746 MT-Level MT-Safe
747 _
748 Standard See below.
749 .TE
750
751 .sp
752 .LP
753 For \fBstrftime()\fR, see \fBstandards\fR(5).
754 .SH SEE ALSO
755 .sp
756 .LP
757 \fBdate\fR(1), \fBctime\fR(3C), \fBmktime\fR(3C), \fBsetlocale\fR(3C),
758 \fBstrptime\fR(3C), \fBtzset\fR(3C), \fBTIMEZONE\fR(4), \fBzoneinfo\fR(4),
759 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
760 .SH NOTES
761 .sp
762 .LP
763 The conversion specification for \fB%V\fR was changed in the Solaris 7 release.
764 This change was based on the public review draft of the ISO C9x standard at
765 that time. Previously, the specification stated that if the week containing 1
766 January had fewer than four days in the new year, it became week 53 of the
767 previous year. The ISO C9x standard committee subsequently recognized that that
768 specification had been incorrect.
769 .sp
770 .LP
771 The conversion specifications for \fB%g\fR, \fB%G\fR, \fB%Eg\fR, \fB%EG\fR, and
772 \fB%Og\fR were added in the Solaris 7 release. This change was based on the
773 public review draft of the ISO C9x standard at that time. These specifications
774 are evolving. If the ISO C9x standard is finalized with a different
775 conclusion, these specifications will change to conform to the ISO C9x standard
776 decision.
777 .sp
778 .LP
779 The conversion specification for \fB%u\fR was changed in the Solaris 8 release.
780 This change was based on the XPG4 specification.
781 .sp
782 .LP
783 If using the \fB%Z\fR specifier and \fBzoneinfo\fR timezones and if the input
784 date is outside the range 20:45:52 UTC, December 13, 1901 to 03:14:07 UTC,
785 January 19, 2038, the timezone name may not be correct.
786 .sp
787 .LP
788 The conversion specification for \fB%+\fR was added in illumos.
789 It is not part of any standard, although it is available on a number
790 of other platforms.
791 Its use is discouraged for conforming applications.
|
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>
21
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
41
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
80
81 .sp
82 .ne 2
83 .na
84 \fB\fB%a\fR\fR
454 .RE
455
456 .sp
457 .ne 2
458 .na
459 \fB\fB%Z\fR\fR
460 .ad
461 .RS 6n
462 Time zone name or abbreviation, or no bytes if no time zone information exists.
463 .RE
464
465 .sp
466 .ne 2
467 .na
468 \fB\fB%+\fR\fR
469 .ad
470 .RS 6n
471 Locale's date and time representation as produced by \fBdate\fR(1).
472 .RE
473
474 .LP
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.
478 .LP
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"
486 .LP
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.
492 .sp
493 .ne 2
494 .na
495 \fB\fB%Ec\fR\fR
496 .ad
497 .RS 7n
498 Locale's alternate appropriate date and time representation.
499 .RE
500
501 .sp
502 .ne 2
503 .na
504 \fB\fB%EC\fR\fR
505 .ad
667 .ne 2
668 .na
669 \fB\fB%OW\fR\fR
670 .ad
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.
674 .RE
675
676 .sp
677 .ne 2
678 .na
679 \fB\fB%Oy\fR\fR
680 .ad
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.
684 .RE
685
686 .SS "Selecting the Output Language"
687 .LP
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"
692 .LP
693 Local time zone information is used as though \fBtzset\fR(3C) were called.
694 .SH RETURN VALUES
695 .LP
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
703 .LP
704 \fBExample 1 \fRAn example of the \fBstrftime()\fR function.
705 .LP
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.
710 .nf
711 .IP
712 \fBstrftime\fR(\fIstr\fR, \fIstrsize\fR, "%A %b %d %j", \fItmptr\fR);
713 .fi
714 .LP
715 This results in \fIstr\fR containing "Thursday Aug 28 240".
716 .SH ATTRIBUTES
717 .LP
718 See \fBattributes\fR(5) for descriptions of the following attributes:
719 .TS
720 box;
721 c | c
722 l | l .
723 ATTRIBUTE TYPE ATTRIBUTE VALUE
724 _
725 CSI Enabled
726 _
727 Interface Stability See below.
728 _
729 MT-Level MT-Safe
730 _
731 Standard See below.
732 .TE
733
734 .LP
735 The \fBstrftime()\fR and \fBstrftime_l()\fR functions are Standard.
736 \fBcftime()\fR and \fBascftime()\fR functions are Committed.
737 .LP
738 For \fBstrftime()\fR and \fBstrftime_l()\fR, see \fBstandards\fR(5).
739 .SH SEE ALSO
740 .LP
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
746 .LP
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.
753 .LP
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.
759 .LP
760 The conversion specification for \fB%u\fR was changed in the Solaris 8 release.
761 This change was based on the XPG4 specification.
762 .LP
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.
766 .LP
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.
|