Guardian Native C Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
Guardian Native C Library Calls (s) strftime(3)
X The time is output in the format specified for the current
locale.
y The year is output as a number (without the century)
between 00 and 99.
Y The year is output as a number (with the century) between
0000 and 9999.
Z The (standard time or daylight saving time) time-zone name
is output as a string from the environment variable TZ
(CDT, for example). If no time-zone information exists, no
characters are output.
% The %(percent) character is output.
When a conversion code character is not from the preceding list, the behavior of this function is
undefined.
EXAMPLES
The following example shows the use of strftime() to display the current date:
#include <time.h>
#include <locale.h>
#include <stdio.h>
#define SLENGTH 80
main()
{
char nowstr[SLENGTH];
time_t nowbin;
struct tm *nowstruct;
(void)setlocale(LC_ALL, "");
if (time(&nowbin) == (time_t) - 1)
printf("Could not get time of day from time()\n");
nowstruct = localtime(&nowbin);
if (strftime(nowstr, SLENGTH, "%A %x", nowstruct) == (size_t) 0)
printf("Could not get string from strftime()\n");
printf("Today’s date is %s\n", nowstr);
}
NOTES
The %S seconds field can contain a value up to 61 seconds rather than up to 59 seconds to allow
leap seconds that are sometimes added to years to keep clocks in correspondence with the solar
year.
RETURN VALUES
The strftime() function returns the number of bytes written into the array pointed to by the s
parameter when the total number of resulting bytes, including the terminating null character, is
not more than the value of the maxsize parameter. The returned value does not count the ter-
minating null byte in the number of bytes written into the array. Otherwise, a value of 0 (zero)
cast to size_t is returned and the contents of the array are undefined.
527192-018 Hewlett-Packard Company 6−101