Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

strftime - Locale-specific representation of date and time

&pagelevel(4)&pagelevel

Definition

#include <time.h>

size_t strftime(char *s, size_t max_n, const char *format, const struct tm *tm_p);

strftime writes a maximum of max_n characters according to the information in the format string to the area to which s points.
The format string consists of any ordinary characters and conversion characters (beginning with %). All ordinary characters, including the terminating null byte (\0), are transferred 1:1 to the string. The conversion characters are replaced by appropriate date/time information.
This information is determined by the current locale (category LC_TIME) and the values of the structure to which tm_p points.

Parameters      

char *s

Result string. It must be large enough to take max_n characters, including the null byte.

size_t max_n

Maximum number of characters, including the null byte, to be written to the result string.

const char *format

Format string containing the ordinary characters and conversion characters. The conversion characters are replaced by locale-specific and current data as described below:

%a

Abbreviated locale-specific name of the weekday.

%A

Full locale-specific name of the weekday.

%b

Abbreviated locale-specific name of the month.

%B

Full locale-specific name of the month.

%c

Locale-specific representation of the time and date.

%d

Day of the month as a decimal number (01 - 31).

%H

Hour as a decimal number (00 - 23). 24-hour clock.

%I

Day of the year as a decimal number (001 - 366).

%j

Tag des Jahres als Dezimalzahl (001 - 366).

%m

Month as a decimal number (01 - 12).

%M

Minutes as a decimal number (00 - 59).

%p

Locale-specific equivalent for AM and PM.

%S

Seconds as a decimal number (00 - 59).

%U

Week number in the year (00 - 53).
The first week starts with the first Sunday in the year.

%w

Weekday as a decimal number (0 - 6). Sunday is 0.

%W

Week number in the year (00 - 53).
The first week starts with the first Monday in the year.

%x

Locale-specific date representation.

%X

Locale-specific time representation.

%y

Year without century as a decimal number (00 - 99).

%Y

Year with century.

%Z

Name of the time zone or no character if the time zone cannot be determined.

%%

The character %.

const struct tm *tm_p

Pointer to a structure of type tm from which strftime can take the time and the date. A structure of type tm is returned by the gmtime, gmtime64, localtime, local-time64, mktime and mktime64 functions.

Return val.   

Number of characters written excluding the terminating null byte.



if successful.


0     

if an error occurs. If, for example, conversion produces more than max_n characters (including the null byte).

Notes

The behavior is undefined if memory areas overlap.

The available locales are described in chapter “Locale”..

See also

gmtime, gmtime64, localtime, localtime64, mktime, mktime64, setlocale