Skip to content
Search

C:strftime

lastmod 2023-09-05created 2016-04-125 edits

Format time as string

Syntax

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

Copies into ptr the content of format, expanding its format specifiers into the corresponding values that represent the time described in timeptr, with a limit of maxsize characters.

Format

%a

Abbreviated weekday name.

%A

Full weekday name.

%b

Abbreviated month name.

%B

Full month name.

%c

Date/time in the locale's format.

%C

Century number [00-99]: the year divided by 100 and truncated to an integer.

%d

Day of the month [01-31].

%D

Date format (same as %m/%d/%y).

%e

Same as %d, except that single digits are preceded by a space [1-31].

%g

Two-digit year portion of the ISO week date [00,99].

%F

ISO date format (same as %Y-%m-%d).

%G

Four-digit year portion of the ISO week date. May be negative.

%h

Same as %b.

%H

Hour in 24-hour format [00-23].

%I

Hour in 12-hour format [01-12].

%j

Day of the year [001-366].

%m

Month [01-12].

%M

Minute [00-59].

%n

Newline character.

%p

AM or PM string.

%r

Time in the locale's AM/PM format. If the locale time format is not available, the default is the POSIX AM/PM time format (%I:%M:%S %p).

%R

24-hour format without seconds (same as %H:%M).

%S

Second [00-61]. The range of seconds allows for leap seconds and double leap seconds.

%t

Tab character.

%T

24-hour format with seconds (same as %H:%M:%S).

%u

Weekday [1,7]. Monday is 1 and Sunday is 7.

%U

Week number of the year [00-53]. Sunday is the first day of the week.

%V

ISO week number of the year [01-53]. Monday is the first day of the week. If the week containing January 1 has four or more days in the new year, it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1 of the new year.

%w

Weekday [0,6]. Sunday is 0.

%W

Week number of the year [00-53]. Monday is the first day of the week.

%x

Date in the locale's format.

%X

Time in the locale's format.

%y

Two-digit year [00,99].

%Y

Four-digit year. May be negative.

%z

UTC offset. The output is a string of the form +HHMM or -HHMM, where + means east of GMT and - means west of GMT. HH is the number of hours from GMT and MM is the number of minutes from GMT.

%Z

Time zone name.

%%

% character.

Commonly used filename-safe format: %Y%m%d-%H%M%S%z (the time part is all uppercase)

See also

Favorite site

author Zer0 sitemap