Skip navigation.

ATMI C Function Reference

  Previous Next vertical dots separating previous/next from contents/index/pdf Contents View as PDF   Get Adobe Reader

 


strftime(3c)

Name

strftime()—Converts date and time to string.

Synopsis

#include <time.h>

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

Description

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. All ordinary characters (including the terminating NULL character) are copied unchanged into the array. For strftime(), no more than maxsize characters are placed into the array.

If format is (char *)0, then the locale's default format is used. The default format is the same as "%c".

Each directive 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.

Character

Description

%%

Same as %

%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 appropriate date and time representation

%C

Locale's date and time representation as produced by date(1)

%d

Day of month ( 01 - 31 )

%D

Date as %m/%d/%y

%e

Day of month (1-31; single digits are preceded by a blank)

%h

Locale's abbreviated month name.

%H

Hour ( 00 - 23 )

%I

Hour ( 01 - 12 )

%j

Day number of year ( 001 - 366 )

%m

Month number ( 01 - 12 )

%M

Minute ( 00 - 59 )

%n

Same as \

%p

Locale's equivalent of either AM or PM

%r

Time as %I:%M:%S [AM|PM]

%R

Time as %H:%M

%S

Seconds ( 00 - 61 ), allows for leap seconds

%t

Insert a tab

%T

Time as %H:%M:%S

%U

Week number of year ( 00 - 53 ), Sunday is the first day of week 1

%w

Weekday number ( 0 - 6 ), Sunday = 0

%W

Week number of year ( 00 - 53 ), Monday is the first day of week 1

%x

Locale's appropriate date representation

%X

Locale's appropriate time representation

%y

Year within century ( 00 - 99 )

%Y

Year as ccyy (for example, 1986)

%Z

Time zone name or no characters if no time zone exists


 

The difference between %U and %W lies in which day is counted as the first of the week. Week number 01 is the first week in January starting with a Sunday for %U or a Monday for %W. Week number 00 contains those days before the first Sunday or Monday in January for %U and %W, respectively.

If the total number of resulting characters including the terminating NULL character is not more than maxsize, strftime(), returns the number of characters placed into the array pointed to by s not including the terminating NULL character. Otherwise, zero is returned and the contents of the array are indeterminate.

A thread in a multithreaded application may issue a call to strftime() while running in any context state, including TPINVALIDCONTEXT.

Selecting the Output Language

By default, the output of strftime(), appears in U.S. English. The user can request that the output of strftime() be in a specific language by setting the locale for category LC_TIME in setlocale().

Time Zone

The time zone is taken from the environment variable TZ. See ctime(3c) for a description of TZ.

Examples

The example illustrates the use of strftime(). 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 in New Jersey.

strftime (str, strsize, "%A %b %d %j", tmptr)

This results in str containing "Thursday Aug 28 240".

Files

$TUXDIR/locale/locale/LANGINFO—file containing compiled locale-specific date and time information

See Also

mklanginfo(1), setlocale(3c)

 

Skip navigation bar  Back to Top Previous Next