Python strftime tokens.

Python's datetime.strftime inherits the C strftime vocabulary with documented additions (%f). There are no portable unpadded-number tokens: the %-d and %-m forms work on glibc and macOS but fail on Windows, so this table lists only what the documentation guarantees. Month and weekday names follow the process locale, not an argument. There is no %s in the documentation — use datetime.timestamp() for a unix timestamp.

TokenMeansExample
%YFour-digit year

Not zero-padded below year 1000 on all platforms.

2006
%yTwo-digit year06
%mMonth number, padded01
%bMonth name, abbreviatedJan
%BMonth name, fullJanuary
%dDay of month, padded02
%aWeekday, abbreviatedMon
%AWeekday, fullMonday
%jDay of year

Zero-padded to three digits (002).

2
%VWeek of year

ISO-8601 week. %U (Sunday-first) and %W (Monday-first) count differently — all three disagree around New Year.

1
%GISO week-based year

Pairs with %V; using %Y next to %V is the classic New-Year bug.

2006
%HHour, 24-hour clock, padded15
%IHour, 12-hour clock, padded03
%pAM/PM marker

Locale-dependent; empty in some locales that don't use day periods.

PM
%MMinute, padded04
%SSecond, padded05
%fFractional seconds

Always six digits (microseconds), never three.

000
%zUTC offset, basic

Empty string for naive datetimes; can include seconds/microseconds for exotic offsets.

-0700
%:zUTC offset, extended

Added in Python 3.12; earlier versions need manual slicing.

-07:00
%ZTime-zone name, short

Empty for naive datetimes; the name comes from the tzinfo object.

MST

Examples render the reference instant, Mon, Jan 2 2006, 3:04:05 PM MST.

Literal text

A literal percent sign is written %%. All other text passes through unchanged; unknown %-sequences are platform-defined, so don't rely on them surviving.

Verified against Python docs — strftime() and strptime() format codes.

Translate Python strftime