Name

strftime function — Formats a time as a string

Synopsis

size_t strftime(char* str, size_t n, const char* fmt, const tm* tmptr)

The strftime function formats a tm object as a string. Up to n bytes are stored in str, including a terminating null character. The return value is the number of characters actually stored, not counting the final null character. If the formatted result requires more than n characters, the return value is 0.

Characters from fmt are copied to str, except conversion specifiers, which start with a percent sign (%) and are followed by one of the letters shown in Table 13-6. The LC_TIME category in the current C locale controls the text that is copied to str for each conversion specifier.

Table 13-6. Conversion specifiers for strftime

Specifier

Description

a

Abbreviated weekday name

A

Full weekday name

b

Abbreviated month name

B

Full month name

C

Complete date and time

D

Day of the month (01-31)

H

Hour (00-23); 24-hour clock

I

Hour (01-12); 12-hour clock

j

Day of the year (001-366)

m

Month (01-12)

M

Minutes (00-59)

P

A.M./P.M. designation for use with a 12-hour clock

S

Second (00-61); up to two leap seconds

U

Week number (00-53); week 1 starts with the first Sunday

w

Weekday (0-6); Sunday is day 0

W

Week number (00-53); week 1 starts with first Monday

x

Date

X

Time

y

Year in century (00-99)

Y

Year

Z

Time zone name or abbreviation, or empty string if time zone is unknown

%

Literal %

Get C++ In a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.