Name

strftime

Synopsis

strftime(fmt[,tupletime])

Accepts an instant expressed as a nine-item tuple in local time and returns a string that represents tupletime as specified by string fmt. If you omit tupletime, strftime uses localtime(time( )) instead (i.e., it formats the current time instant in the local time zone). The syntax of string format is similar to the syntax specified in Section 9.3. However, conversion characters are different, as shown in Table 12-2, and refer to the time instant specified by tupletime. Specifying width and precision explicitly works on some platforms, but not on all.

Table 12-2. Conversion characters for strftime

Type char

Meaning

Special notes

a

Weekday name, abbreviated

Depends on locale

A

Weekday name, full

Depends on locale

b

Month name, abbreviated

Depends on locale

B

Month name, full

Depends on locale

c

Complete date and time representation

Depends on locale

d

Day of the month

Between 1 and 31

H

Hour (24-hour clock)

Between 0 and 23

I

Hour (12-hour clock)

Between 1 and 12

j

Day of the year

Between 1 and 366

m

Month number

Between 1 and 12

M

Minute number

Between 0 and 59

p

`AM’ or `PM’ equivalent

Depends on locale

S

Second number

Between 0 and 61

U

Week number (Sunday first weekday)

Between 0 and 53

w

Weekday number

0 is Sunday, up to 6

W

Week number (Monday first weekday)

Between 0 and 53

x

Complete date representation

Depends on locale

X

Complete time representation

Depends on locale

Get Python 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.