STRFTIME(3C) | Standard C Library Functions | STRFTIME(3C) |
#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().
%%
%a
%A
%b
%B
%c
%a %b %e %H:%M:%S %Y
Other locales may have different locale-specific formats.
%C
%d
%D
%e
%F
%g
%G
%h
%H
%I
%j
%k
%l
%m
%M
%n
%p
%r
%R
%s
%S
%t
%T
%u
%U
%v
%V
%w
%W
%x
%X
%y
%Y
%z
%Z
%+
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.
%Ec
%EC
%Eg
%EG
%Ex
%EX
%Ey
%EY
%Od
%Oe
%Og
%OH
%OI
%Om
%OM
%OS
%Ou
%OU
%Ow
%OW
%Oy
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.
August 20, 2019 |