Print this page
2964 need POSIX 2008 locale object support
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Gordon Ross <gordon.ross@nexenta.com>
Approved by: TBD
   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, 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 .fi
  25 
  26 .LP
  27 .nf






  28 \fBint\fR \fBcftime\fR(\fBchar *\fR\fIs\fR, \fBchar *\fR\fIformat\fR, \fBconst time_t *\fR\fIclock\fR);
  29 .fi
  30 
  31 .LP
  32 .nf
  33 \fBint\fR \fBascftime\fR(\fBchar *\fR\fIs\fR, \fBconst char *\fR\fIformat\fR,
  34      \fBconst struct tm *\fR\fItimeptr\fR);
  35 .fi
  36 
  37 .SH DESCRIPTION
  38 .sp
  39 .LP
  40 The \fBstrftime()\fR, \fBascftime()\fR, and \fBcftime()\fR functions place

  41 bytes into the array pointed to by \fIs\fR as controlled by the string pointed
  42 to by \fIformat\fR. The \fIformat\fR string consists of zero or more conversion
  43 specifications and ordinary characters.  A conversion specification consists of
  44 a '\fB%\fR' (percent) character and one or two terminating conversion
  45 characters that determine the conversion specification's behavior.  All
  46 ordinary characters (including the terminating null byte) are copied unchanged
  47 into the array pointed to by \fIs\fR. If copying takes place between objects
  48 that overlap, the behavior is undefined. For \fBstrftime()\fR, no more than
  49 \fImaxsize\fR bytes are placed into the array.
  50 .sp

  51 .LP
  52 If \fIformat\fR is \fB(char *)0\fR, then the locale's default format is used.
  53 For \fBstrftime()\fR the default format is the same as \fB%c\fR; for
  54 \fBcftime()\fR and \fBascftime()\fR the default format is the same as \fB%+\fR.
  55 \fBcftime()\fR and \fBascftime()\fR first try to use the value of the
  56 environment variable \fBCFTIME\fR, and if that is undefined or empty, the
  57 default format is used.
  58 .sp
  59 .LP
  60 Each conversion specification is replaced by appropriate characters as
  61 described in the following list. The appropriate characters are determined by
  62 the \fBLC_TIME\fR category of the program's locale and by the values contained
  63 in the structure pointed to by \fItimeptr\fR for \fBstrftime()\fR and
  64 \fBascftime()\fR, and by the time represented by \fIclock\fR for
  65 \fBcftime()\fR.
  66 .sp
  67 .ne 2
  68 .na
  69 \fB\fB%%\fR\fR
  70 .ad
  71 .RS 6n
  72 Same as \fB%\fR.
  73 .RE
  74 
  75 .sp
  76 .ne 2
  77 .na
  78 \fB\fB%a\fR\fR


 448 .RE
 449 
 450 .sp
 451 .ne 2
 452 .na
 453 \fB\fB%Z\fR\fR
 454 .ad
 455 .RS 6n
 456 Time zone name or abbreviation, or no bytes if no time zone information exists.
 457 .RE
 458 
 459 .sp
 460 .ne 2
 461 .na
 462 \fB\fB%+\fR\fR
 463 .ad
 464 .RS 6n
 465 Locale's date and time representation as produced by \fBdate\fR(1).
 466 .RE
 467 
 468 .sp
 469 .LP
 470 If a conversion specification does not correspond to any of the above or to any
 471 of the modified conversion specifications listed below, the behavior is
 472 undefined and \fB0\fR is returned.
 473 .sp
 474 .LP
 475 The difference between \fB%U\fR and \fB%W\fR (and also between modified
 476 conversion specifications \fB%OU\fR and \fB%OW\fR) lies in which day is counted
 477 as the first of the week. Week number 1 is the first week in January starting
 478 with a Sunday for \fB%U\fR or a Monday for \fB%W\fR. Week number 0 contains
 479 those days before the first Sunday or Monday in January for \fB%U\fR and
 480 \fB%W\fR, respectively.
 481 .SS "Modified Conversion Specifications"
 482 .sp
 483 .LP
 484 Some conversion specifications can be modified by the \fBE\fR and \fBO\fR
 485 modifiers to indicate that an alternate format or specification should be used
 486 rather than the one normally used by the unmodified conversion specification.
 487 If the alternate format or specification does not exist in the current locale,
 488 the behavior will be as if the unmodified specification were used.
 489 .sp
 490 .ne 2
 491 .na
 492 \fB\fB%Ec\fR\fR
 493 .ad
 494 .RS 7n
 495 Locale's alternate appropriate date and time representation.
 496 .RE
 497 
 498 .sp
 499 .ne 2
 500 .na
 501 \fB\fB%EC\fR\fR
 502 .ad


 664 .ne 2
 665 .na
 666 \fB\fB%OW\fR\fR
 667 .ad
 668 .RS 7n
 669 Week number of the year (Monday as the first day of the week) using the
 670 locale's alternate numeric symbols.
 671 .RE
 672 
 673 .sp
 674 .ne 2
 675 .na
 676 \fB\fB%Oy\fR\fR
 677 .ad
 678 .RS 7n
 679 Year (offset from \fB%C\fR) in the locale's alternate representation and using
 680 the locale's alternate numeric symbols.
 681 .RE
 682 
 683 .SS "Selecting the Output Language"
 684 .sp
 685 .LP
 686 By default, the output of \fBstrftime()\fR, \fBcftime()\fR, and
 687 \fBascftime()\fR appear in U.S. English. The user can request that the output
 688 of \fBstrftime()\fR, \fBcftime()\fR, or \fBascftime()\fR be in a specific
 689 language by setting the \fBLC_TIME\fR category using \fBsetlocale()\fR.
 690 .SS "Time Zone"
 691 .sp
 692 .LP
 693 Local time zone information is used as though \fBtzset\fR(3C) were called.
 694 .SH RETURN VALUES
 695 .sp
 696 .LP
 697 The \fBstrftime()\fR, \fBcftime()\fR, and \fBascftime()\fR functions return the
 698 number of characters placed into the array pointed to by \fIs\fR, not including
 699 the terminating null character. If the total number of resulting characters
 700 including the terminating null character is more than \fImaxsize\fR,
 701 \fBstrftime()\fR returns \fB0\fR and the contents of the array are
 702 indeterminate.
 703 .SH EXAMPLES
 704 .LP
 705 \fBExample 1 \fRAn example of the \fBstrftime()\fR function.
 706 .sp
 707 .LP
 708 The following example illustrates the use of \fBstrftime()\fR for the
 709 \fBPOSIX\fR locale. It shows what the string in \fIstr\fR would look like if
 710 the structure pointed to by \fItmptr\fR contains the values corresponding to
 711 Thursday, August 28, 1986 at 12:44:36.
 712 
 713 .sp
 714 .in +2
 715 .nf
 716 \fBstrftime (str, strsize, "%A %b %d %j", tmptr)\fR

 717 .fi
 718 .in -2
 719 
 720 .sp
 721 .LP
 722 This results in \fIstr\fR containing "Thursday Aug 28 240".
 723 
 724 .SH ATTRIBUTES
 725 .sp
 726 .LP
 727 See \fBattributes\fR(5) for descriptions of the following attributes:
 728 .sp
 729 
 730 .sp
 731 .TS
 732 box;
 733 c | c
 734 l | l .
 735 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 736 _
 737 CSI     Enabled
 738 _
 739 Interface Stability     Committed
 740 _
 741 MT-Level        MT-Safe
 742 _
 743 Standard        See below.
 744 .TE
 745 
 746 .sp
 747 .LP
 748 For \fBstrftime()\fR, see \fBstandards\fR(5).



 749 .SH SEE ALSO
 750 .sp
 751 .LP
 752 \fBdate\fR(1), \fBctime\fR(3C), \fBmktime\fR(3C), \fBsetlocale\fR(3C),
 753 \fBstrptime\fR(3C), \fBtzset\fR(3C), \fBTIMEZONE\fR(4), \fBzoneinfo\fR(4),

 754 \fBattributes\fR(5), \fBenviron\fR(5), \fBstandards\fR(5)
 755 .SH NOTES
 756 .sp
 757 .LP
 758 The conversion specification for \fB%V\fR was changed in the Solaris 7 release.
 759 This change was based on the public review draft of the ISO C9x standard at
 760 that time. Previously, the specification stated that if the week containing 1
 761 January had fewer than four days in the new year, it became week 53 of the
 762 previous year. The ISO C9x standard committee subsequently recognized that that
 763 specification had been incorrect.
 764 .sp
 765 .LP
 766 The conversion specifications for \fB%g\fR, \fB%G\fR, \fB%Eg\fR, \fB%EG\fR, and
 767 \fB%Og\fR were added in the Solaris 7 release.  This change was based on the
 768 public review draft of the ISO C9x standard at that time. These specifications
 769 are evolving.  If the ISO C9x standard is finalized with a different
 770 conclusion, these specifications will change to conform to the ISO C9x standard
 771 decision.
 772 .sp
 773 .LP
 774 The conversion specification for \fB%u\fR was changed in the Solaris 8 release.
 775 This change was based on the XPG4 specification.
 776 .sp
 777 .LP
 778 If using the \fB%Z\fR specifier and \fBzoneinfo\fR timezones and if the input
 779 date is outside the range 20:45:52 UTC, December  13, 1901 to 03:14:07 UTC,
 780 January 19, 2038, the timezone name may not be correct.
 781 .sp
 782 .LP
 783 The conversion specification for \fB%+\fR was added in illumos.
 784 It is not part of any standard, although it is available on a number
 785 of other platforms.
 786 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.