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
http://www.opengroup.org/bookstore/.
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 SunOS 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.
This notice shall appear on any product containing this material.
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.
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.
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]
Copyright 1989 AT&T
Portions Copyright (c) 1992, X/Open Company Limited. All Rights Reserved.
Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
Copyright (c) 2014 Gary Mills
Copyright 2014 Garrett D'Amore <garrett@damore.org>
#include <time.h> size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
size_t strftime_l(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr, locale_t loc);
int cftime(char *s, char *format, const time_t *clock);
int ascftime(char *s, const char *format, const struct tm *timeptr);
If format is NULL, then the locale's default format is used. For strftime() the default format is the same as %c; for cftime() and ascftime() the default format is the same as %+. cftime() and ascftime() first try to use the value of the environment variable CFTIME, and if that is undefined or empty, the default format is used.
Each conversion specification is replaced by appropriate characters as described in the following list. The appropriate characters are determined by the LC_TIME category of the program's locale and by the values contained in the structure pointed to by timeptr for strftime() and ascftime(), and by the time represented by clock for cftime(). %%
Same as %.
Locale's abbreviated weekday name.
Locale's full weekday name.
Locale's abbreviated month name.
Locale's full month name.
Locale's appropriate date and time representation. In the C locale, this format is:
%a %b %e %H:%M:%S %YOther locales may have different locale-specific formats.
Century number (the year divided by 100 and truncated to an integer as a decimal number [01,99]).
Day of month [01,31].
Date as %m/%d/%y.
Day of month [1,31]; single digits are preceded by a space.
Equivalent to %Y-%m-%d (the ISO 8601:2000 standard date format).
Week-based year within century [00,99].
Week-based year, including the century [0000,9999].
Locale's abbreviated month name.
Hour (24-hour clock) [00,23].
Hour (12-hour clock) [01,12].
Day number of year [001,366].
Hour (24-hour clock) [0,23]; single digits are preceded by a space.
Hour (12-hour clock) [1,12]; single digits are preceded by a space.
Month number [01,12].
Minute [00,59].
Insert a NEWLINE.
Locale's equivalent of either a.m. or p.m.
Appropriate time representation in 12-hour clock format with %p.
Time as %H:%M.
Seconds since 00:00:00 UTC, January 1, 1970.
Seconds [00,60]; the range of values is [00,60] rather than [00,59] to allow for the occasional leap second.
Insert a TAB.
Time as %H:%M:%S.
Weekday as a decimal number [1,7], with 1 representing Monday. See NOTES below.
Week number of year as a decimal number [00,53], with Sunday as the first day of week 1.
Date as %e-%b-%Y.
The ISO 8601 week number as a decimal number [01,53]. In the ISO 8601 week-based system, weeks begin on a Monday and week 1 of the year is the week that includes both January 4th and the first Thursday of the year. If the first Monday of January is the 2nd, 3rd, or 4th, the preceding days are part of the last week of the preceding year. See NOTES below.
Weekday as a decimal number [0,6], with 0 representing Sunday.
Week number of year as a decimal number [00,53], with Monday as the first day of week 1.
Locale's appropriate date representation.
Locale's appropriate time representation.
Year within century [00,99].
Year, including the century (for example 1993).
Replaced by offset from UTC in ISO 8601:2000 standard format (+hhmm or -hhmm), or by no characters if no time zone is determinable. For example, "-0430" means 4 hours 30 minutes behind UTC (west of Greenwich). If tm_isdst is zero, the standard time offset is used. If tm_isdst is greater than zero, the daylight savings time offset if used. If tm_isdst is negative, no characters are returned.
Time zone name or abbreviation, or no bytes if no time zone information exists.
Locale's date and time representation as produced by date(1).
If a conversion specification does not correspond to any of the above or to any of the modified conversion specifications listed below, the behavior is undefined and 0 is returned.
The difference between %U and %W (and also between modified conversion specifications %OU and %OW) lies in which day is counted as the first of the week. Week number 1 is the first week in January starting with a Sunday for %U or a Monday for %W. Week number 0 contains those days before the first Sunday or Monday in January for %U and %W, respectively.
Locale's alternate appropriate date and time representation.
Name of the base year (period) in the locale's alternate representation.
Offset from %EC of the week-based year in the locale's alternative representation.
Full alternative representation of the week-based year.
Locale's alternate date representation.
Locale's alternate time representation.
Offset from %EC (year only) in the locale's alternate representation.
Full alternate year representation.
Day of the month using the locale's alternate numeric symbols.
Same as %Od.
Week-based year (offset from %C) in the locale's alternate representation and using the locale's alternate numeric symbols.
Hour (24-hour clock) using the locale's alternate numeric symbols.
Hour (12-hour clock) using the locale's alternate numeric symbols.
Month using the locale's alternate numeric symbols.
Minutes using the locale's alternate numeric symbols.
Seconds using the locale's alternate numeric symbols.
Weekday as a number in the locale's alternate numeric symbols.
Week number of the year (Sunday as the first day of the week) using the locale's alternate numeric symbols.
Number of the weekday (Sunday=0) using the locale's alternate numeric symbols.
Week number of the year (Monday as the first day of the week) using the locale's alternate numeric symbols.
Year (offset from %C) in the locale's alternate representation and using the locale's alternate numeric symbols.
The following example illustrates the use of strftime() for the POSIX locale. It shows what the string in str would look like if the structure pointed to by tmptr contains the values corresponding to Thursday, August 28, 1986 at 12:44:36.
strftime(str, strsize, "%A %b %d %j", tmptr);
This results in str containing "Thursday Aug 28 240".
ATTRIBUTE TYPE ATTRIBUTE VALUE |
CSI Enabled |
Interface Stability See below. |
MT-Level MT-Safe |
Standard See below. |
The strftime() and strftime_l() functions are Standard. cftime() and ascftime() functions are Committed.
For strftime() and strftime_l(), see standards(5).
The conversion specifications for %g, %G, %Eg, %EG, and %Og were added in the Solaris 7 release. This change was based on the public review draft of the ISO C9x standard at that time. The %g and %G specifications were adopted in the formal standard. The other two were not, and should not be used in portable applications.
The conversion specification for %u was changed in the Solaris 8 release. This change was based on the XPG4 specification.
If using the %Z specifier and zoneinfo timezones and if the input date is outside the range 20:45:52 UTC, December 13, 1901 to 03:14:07 UTC, January 19, 2038, the timezone name may not be correct.
The conversion specification for %+ was added in illumos. It is not part of any standard, although it is available on a number of other platforms. Its use is discouraged for conforming applications.