#include <time.h> size_t strftime(char *s, size_t maxsize, const char *format, const struct tm *timep);
strftime
converts a time value into a string according to the
format specified by format
. The string is placed in the array
pointed to by s
. No more than maxsize
characters are placed
into the array.
The format is a character sequence consisting of zero or more conversion specifications and regular characters. The conversion specifications are described below; ordinary characters, including the terminating-null character, are copied into the string without being converted.
The conversion specifications for format
are as follows.
Remember that the behavior of these specifications depend on the
current locale. (See Chapter 10, "Localization," in the SAS/C Library Reference, Volume 2 for more
information on locales.) The "C" locale values for each of the
specifications below are listed in Chapter 2, "Language Definition,"
in the SAS/C Compiler and Library User's Guide, Fourth Edition . strftime
is affected by time zone information contained
in the TZ
environment variable, if it is defined.
See Chapter 10, "Localization," in the SAS/C Library Reference, Volume 2 for a discussion of how locale
affects the behavior of strftime
. See Chapter 11, "Multibyte Character
Functions," in the SAS/C Library Reference, Volume 2 for a discussion of the relationship between the format
string for strftime
and multibyte characters.
maxsize
characters, including
the terminating-null character, strftime
returns the number of resulting
characters. This return value does not include the terminating-null character.
If the conversion results in more than maxsize
characters,
strftime
returns 0. In this case, the contents of the array pointed to
by s
are indeterminate. The return value will be zero also if
strftime
is given an invalid format specifier, or if strftime
fails
for some reason other than the conversion resulting in more than maxsize
characters.
strftime
is undefined.
If a conversion specification is not one of those listed above or some other
error occurs while processing a specification, strftime
issues a
diagnostic, null terminates the conversion output array up to the specification
that caused the error, and returns 0.
#include <time.h> #include <stdio.h> main() { time_t now; struct tm *tm_ptr; char date_str[80]; size_t nchar; time(&now); /* Obtain today's date/time. */ tm_ptr = localtime(&now); /* Convert value to a tm struct. */ nchar = strftime(date_str, sizeof(date_str), "Today is %A, %B %d, %Y and %I:%M:%S %p is the time.", tm_ptr); printf("%.80s", date_str); }
asctime
, tzset
Copyright (c) 1998 SAS Institute Inc. Cary, NC, USA. All rights reserved.