United States-English |
|
|
HP-UX Reference > Sstrftime(3C)HP-UX 11i Version 3: February 2007 |
|
NAMEstrftime() — convert date and time to string SYNOPSIS#include <time.h> size_t strftime( char *s, size_t maxsize, const char *format, const struct tm *timeptr ); DESCRIPTIONThe strftime() function converts the contents of a tm structure (see ctime(3C)) to a formatted date and time string. strftime() places characters into the array pointed to by s as controlled by the string pointed to by format. The format string consists of zero or more directives and ordinary characters. A directive consists of a % character, an optional field width and precision specification, and a terminating character that determines the directive's behavior. All ordinary characters (including the terminating null character are copied unchanged into the array. No more than maxsize characters are placed into the array. Each directive is replaced by the appropriate characters as described in the following list. The appropriate characters are determined by the program's locale, by the values contained in the structure pointed to by timeptr, and by the TZ environment variable (see External Influences below). DirectivesThe following directives, shown without the optional field width and precision specification, are replaced by the indicated characters:
The following directives are provided for backward compatibility with the directives supported by date and the ctime() functions. These directives may be removed in a future release. It is recommended that the directives above be used in preference to those below.
If a directive is not one of the above, the behavior is undefined. %g, %G, and %V give values according to the ISO 8601:2000 standard week-based year. In this system, weeks begin on a Monday and week 1 of the year is the week that includes January 4th, which is also the week that includes the first Thursday of the year, and is also the first week that contains at least four days in 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; thus, for Saturday 2nd January 1999, %G is replaced by 1998 and %V is replaced by 53. If December 29th, 30th, or 31st is a Monday, it and any following days are part of week 1 of the following year. Thus, for Tuesday 30th December 1997, %G is replaced by 1998 and %V is replaced by 01. Modified Conversion SpecifiersSome conversion specifiers can be modified by the E or O modifier characters to indicate that an alternative format or specification should be used rather than the one normally used by the unmodified conversion specifier. If the alternative format or specification does not exist for the current locale, the behavior will be as if the unmodified conversion specification were used. Alternative numeric symbols refers to those symbols defined by the ALT_DIGIT (see langinfo(5)) in the locale.
Field Width and PrecisionAn optional field width and precision specification can immediately follow the initial % of a directive in the following order:
If no field width or precision is specified for a d, H, I, m, M, S, U, W, y, or j directive, a default of .2 is used for all but j for which .3 is used. EXTERNAL INFLUENCESLocaleThe LC_TIME category determines the characters to be substituted for those directives described above as being from the locale. The LC_CTYPE category determines the interpretation of the bytes within format as single and/or multi-byte characters. The LC_NUMERIC category determines the characters used to form numbers for those directives that produce numbers in the output. If ALT_DIGITS (see langinfo(5)) is defined for the locale, the characters so specified are used in place of the default ASCII characters. If both ALT_DIGITS and ALT_DIGIT is defined for the locale, ALT_DIGITS will take precedence over ALT_DIGIT. Environment VariablesTZ determines the time zone name substituted for the %Z directive. The time zone name is determined by calling the function tzset() which sets the external variable tzname (see ctime(3C)). RETURN VALUEIf the total number of resulting bytes including the terminating null byte is not more than maxsize, strftime() returns the number of bytes placed into the array pointed to by s, not including the terminating null byte. Otherwise, zero is returned and the contents of the array are indeterminate. EXAMPLESIf the timeptr argument contains the following values: timeptr->tm_sec = 4; timeptr->tm_min = 9; timeptr->tm_hour = 15; timeptr->tm_mday = 4; timeptr->tm_mon = 6; timeptr->tm_year = 88; timeptr->tm_wday = 1; timeptr->tm_yday = 185; timeptr->tm_isdst = 1; the following combinations of the LC_TIME category and format strings produce the indicated output:
* The directives used in these examples are not affected by the LC_TIME category of the locale. WARNINGSIf the arguments s and format are defined such that they overlap, the behavior is undefined. The function tzset() is called upon every invocation of strftime() (whether or not the time zone name is copied to the output array). The range of values for %S ([0,61]) extends to 61 to allow for the occasional one or two leap seconds. However, the system does not accumulate leap seconds and the tm structure generated by the functions localtime() and gmtime() (see ctime(3C)) never reflects any leap seconds. Results are undefined if values contained in the structure pointed to by timeptr exceed the ranges defined for the tm structure (see ctime(3C)) or are not consistent (such as if the tm_yday element is set to 0, indicating the first day of January, while the tm_mon element is set to 11, indicating a day in December). |
Printable version | ||
|