1. Tools
  2. Python strftime cheatsheet

Python strftime cheatsheet

Code

%a

Example

Sun

Description

Weekday as locale's abbreviated name.

Code

%A

Example

Sunday

Description

Weekday as locale's full name.

Code

%w

Example

0

Description

Weekday as a decimal number, where 0 is Sunday and 6 is Saturday.

Code

%d

Example

08

Description

Day of the month as a zero-padded decimal number.

Code

%-d

Example

8

Description

Day of the month as a decimal number. (Platform specific)

Code

%b

Example

Sep

Description

Month as locale's abbreviated name.

Code

%B

Example

September

Description

Month as locale's full name.

Code

%m

Example

09

Description

Month as a zero-padded decimal number.

Code

%-m

Example

9

Description

Month as a decimal number. (Platform specific)

Code

%y

Example

13

Description

Year without century as a zero-padded decimal number.

Code

%Y

Example

2013

Description

Year with century as a decimal number.

Code

%H

Example

07

Description

Hour (24-hour clock) as a zero-padded decimal number.

Code

%-H

Example

7

Description

Hour (24-hour clock) as a decimal number. (Platform specific)

Code

%I

Example

07

Description

Hour (12-hour clock) as a zero-padded decimal number.

Code

%-I

Example

7

Description

Hour (12-hour clock) as a decimal number. (Platform specific)

Code

%p

Example

AM

Description

Locale's equivalent of either AM or PM.

Code

%M

Example

06

Description

Minute as a zero-padded decimal number.

Code

%-M

Example

6

Description

Minute as a decimal number. (Platform specific)

Code

%S

Example

05

Description

Second as a zero-padded decimal number.

Code

%-S

Example

5

Description

Second as a decimal number. (Platform specific)

Code

%f

Example

000000

Description

Microsecond as a decimal number, zero-padded to 6 digits.

Code

%z

Example

+0000

Description

UTC offset in the form ±HHMM[SS[.ffffff]] (empty string if the object is naive).

Code

%Z

Example

UTC

Description

Time zone name (empty string if the object is naive).

Code

%j

Example

251

Description

Day of the year as a zero-padded decimal number.

Code

%-j

Example

251

Description

Day of the year as a decimal number. (Platform specific)

Code

%U

Example

36

Description

Week number of the year (Sunday as the first day of the week) as a zero-padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0.

Code

%-U

Example

36

Description

Week number of the year (Sunday as the first day of the week) as a decimal number. All days in a new year preceding the first Sunday are considered to be in week 0. (Platform specific)

Code

%W

Example

35

Description

Week number of the year (Monday as the first day of the week) as a zero-padded decimal number. All days in a new year preceding the first Monday are considered to be in week 0.

Code

%-W

Example

35

Description

Week number of the year (Monday as the first day of the week) as a decimal number. All days in a new year preceding the first Monday are considered to be in week 0. (Platform specific)

Code

%c

Example

Sun Sep 8 07:06:05 2013

Description

Locale's appropriate date and time representation.

Code

%x

Example

09/08/13

Description

Locale's appropriate date representation.

Code

%X

Example

07:06:05

Description

Locale's appropriate time representation.

Code

%%

Example

%

Description

A literal '%' character.

Code has been copied

Platform-specific directives

The full set of format codes supported varies across platforms, because Python calls the platform C library's strftime() function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime(3) documentation.

The Python docs contain all the format codes that the C standard (1989 version) requires, and these work on all platforms with a standard C implementation. Note that the 1999 version of the C standard added additional format codes. These include codes for non-zero-padded numbers, that can be obtained by appending a dash (-) (UNIX) or hash (#) (Windows) after the percent (%) sign.

Source

This cheatsheet was built from the Python standard library strftime documentation. See github.com/mccutchen/strftime.org for the build source code.

By continuing to use this site, you agree to our cookie policy and privacy policy.