strftime, cftime, ascftime - convert date and time to string
#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().
%%
%a
%A
%b
%B
%c
%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).
%c
%a %b %e %H:%M:%S %Y
This is standard-conforming behavior for standards first supported by Solaris 2.4 through Solaris 10.
%C
This is the default behavior as well as standard-conforming behavior for standards first supported by releases prior to Solaris 2.4.
%C
This is standard-conforming behavior for standards first supported by Solaris 2.4 through Solaris 10.
%d
%D
%e
%F
%g
%G
%h
%H
%I
%j
%k
%l
%m
%M
%n
%p
%r
%R
%S
%t
%T
%u
%U
%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.
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.
%Ec
%EC
%Eg
%EG
%Ex
%EX
%Ey
%EY
%Od
%Oe
%Og
%OH
%OI
%Om
%OM
%OS
%Ou
%OU
%Ow
%OW
%Oy
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.
Example 1 An example of the strftime() function.
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:
|
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.
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |