Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ctime(3)

setlocale(3)

strftime(3)

Name

strftime − convert time and date to string

Syntax

#include <time.h>

int strftime (s, maxsize, format, tm)
char *s;
size_t maxsize;
char *format;
struct tm *tm;

Description

The strftime function places characters in the array pointed to by s.  No more than maxsize characters are placed into the array.  The format string controls this process. This string consists of zero or more directives and ordinary characters. A directive consists of a % character followed by a character that determines the behavior of the directive.  All ordinary characters are copied unchanged into the array, including the terminating null character.

Each directive is replaced by the appropriate characters as shown in the following table. The characters are determined by the program’s locale category LC_TIME and the values contained in the structure pointed to by tm. 

Directive Replaced by
%a Locale’s abbreviated weekday name
%A Locale’s full weekday name
%b Locale’s abbreviated month name
%B Locale’s full month name
%c Locale’s date and time representation
%d Day of month as a decimal number (01−31)
%D Date (%m/%d/%y)
%h Locale’s abbreviated month name
%H Hour as a decimal number (00−23)
%I Hour as a decimal number (01−12)
%j Day of year (001−366)
%m Number of month (01−12)
%M Minute number (00−59)
%n Newline character
%p Locale’s equivalent to AM or PM
%r Time in AM/PM notation
%S Second number (00−59)
%t Tab character
%T Time (%H/%M/%S)
%U Week number (00−53), Sunday as first day of week
%w Weekday number (0[Sunday]−6)
%W Week number (00−53), Monday as first day of week
%x Locale’s date representation
%X Locale’s time representation
%y Year without century (00−99)
%Y Year with century
%Z Timezone name, no characters if no timezone
%% %

If a directive is used that is not contained in the table, the results are undefined. 

International Environment

LC_TIMEContains the user’s requirements for language, territory, and codeset for the time format.  LC_TIME affects the behavior of the time functions in strftime. If LC_TIME is not defined in the current environment, LANG provides the necessary default.

LANGIf this environment is set and valid, strftime uses the international language database named in the definition to determine the time formatting rules. If LC_TIME is defined, its definition supercedes the definition of LANG.

Return Values

If the total number of resulting characters, including the terminal null character, is not more than maxsize, the strftime function returns the total of resultant characters placed into the array pointed to by s, not including the terminating null character.  In all other cases zero is returned and the contents of the array are indeterminate. 

As the timezone name is not contained in the tm structure the value returned by %Z is determined by the timezone function, see ctime.

See Also

ctime(3), setlocale(3)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026