Name | Synopsis | Description | Return Values | Examples | Attributes | See Also | Notes
#include <time.h> size_t strftime(char *restrict s, size_t maxsize, const char *restrict format, const struct tm *restrict timeptr);
int cftime(char *s, char *format, const time_t *clock);
int ascftime(char *s, const char *format, const struct tm *timeptr);
The strftime(), ascftime(), and cftime() functions place bytes into the array pointed to by s as controlled by the string pointed to by format. The format string consists of zero or more conversion specifications and ordinary characters. A conversion specification consists of a '%' (percent) character and one or two terminating conversion characters that determine the conversion specification's behavior. All ordinary characters (including the terminating null byte) are copied unchanged into the array pointed to by s. If copying takes place between objects that overlap, the behavior is undefined. For strftime(), no more than maxsize bytes are placed into the array.
If format is (char *)0, 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 %C. 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 represented as:
%a %b %d %H:%M:%S %Y
This is the default behavior as well as standard-conforming behavior for standards first supported by releases prior to Solaris 2.4. See standards(5).
Locale's date and time representation as produced by date(1).
This is the default behavior as well as standard-conforming behavior for standards first supported by releases prior to Solaris 2.4.
Century number (the year divided by 100 and truncated to an integer as a decimal number [01,99]).
This is standard-conforming behavior for standards first supported by Solaris 2.4 through Solaris 10.
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 [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.
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.
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.
Some conversion specifications can be modified by the E and O modifiers to indicate that an alternate format or specification should be used rather than the one normally used by the unmodified conversion specification. If the alternate format or specification does not exist in the current locale, the behavior will be as if the unmodified specification were used.
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.
By default, the output of strftime(), cftime(), and ascftime() appear in U.S. English. The user can request that the output of strftime(), cftime(), or ascftime() be in a specific language by setting the LC_TIME category using setlocale().
Local time zone information is used as though tzset(3C) were called.
The strftime(), cftime(), and ascftime() functions return the number of characters placed into the array pointed to by s, not including the terminating null character. If the total number of resulting characters including the terminating null character is more than maxsize, strftime() returns 0 and the contents of the array are indeterminate.
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”.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE |
ATTRIBUTE VALUE |
---|---|
CSI |
Enabled |
Interface Stability |
Committed |
MT-Level |
MT-Safe |
Standard |
See below. |
For strftime(), see standards(5).
date(1), ctime(3C), mktime(3C), setlocale(3C), strptime(3C), tzset(3C), TIMEZONE(4), zoneinfo(4), attributes(5), environ(5), standards(5)
The conversion specification for %V was changed in the Solaris 7 release. This change was based on the public review draft of the ISO C9x standard at that time. Previously, the specification stated that if the week containing 1 January had fewer than four days in the new year, it became week 53 of the previous year. The ISO C9x standard committee subsequently recognized that that specification had been incorrect.
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. These specifications are evolving. If the ISO C9x standard is finalized with a different conclusion, these specifications will change to conform to the ISO C9x standard decision.
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.
Name | Synopsis | Description | Return Values | Examples | Attributes | See Also | Notes