Home › Docs

Python strftime() cheat sheet & directive reference

Every Python strftime directive with a description and a live example, grouped by what it formats. Examples use datetime(2026, 6, 18, 13, 45, 30).

Open the live tester →

Year

%YYear with century as a decimal number.2026
%yYear without century, zero-padded (00–99).26
%-yplatform-specificYear without century, no leading zero. Platform-specific (Linux/macOS).26
%GISO 8601 week-based year. Use with %V and %u, never with %Y.2026

Month

%mMonth as a zero-padded number (01–12).06
%BFull month name in the current locale.June
%bAbbreviated month name in the current locale.Jun
%-mplatform-specificMonth with no leading zero. Platform-specific (Linux/macOS).6
%hEquivalent to %b (abbreviated month name).Jun

Day

%dDay of the month, zero-padded (01–31).18
%-dplatform-specificDay of the month with no leading zero. Platform-specific (Linux/macOS).18
%jDay of the year, zero-padded (001–366).169
%-jplatform-specificDay of the year with no leading zero. Platform-specific (Linux/macOS).169

Weekday

%AFull weekday name in the current locale.Thursday
%aAbbreviated weekday name in the current locale.Thu
%wWeekday as a decimal number, 0=Sunday … 6=Saturday.4
%uWeekday as a decimal number, 1=Monday … 7=Sunday (ISO 8601).4

Time

%HHour (24-hour clock), zero-padded (00–23).13
%IHour (12-hour clock), zero-padded (01–12).01
%pLocale’s equivalent of AM or PM.PM
%MMinute, zero-padded (00–59).45
%SSecond, zero-padded (00–59; up to 61 historically for leap seconds).30
%-Hplatform-specific24-hour hour with no leading zero. Platform-specific (Linux/macOS).13
%-Iplatform-specific12-hour hour with no leading zero. Platform-specific (Linux/macOS).1
%-Mplatform-specificMinute with no leading zero. Platform-specific (Linux/macOS).45
%-Splatform-specificSecond with no leading zero. Platform-specific (Linux/macOS).30
%fMicrosecond as a decimal number, zero-padded to 6 digits (000000–999999).000000

Time zone

%zUTC offset as ±HHMM (empty if the datetime is naive). 
%ZTime zone name or abbreviation (empty if the datetime is naive). 

Week & ISO

%UWeek of the year, Sunday as the first day (00–53). Days before the first Sunday are week 0.24
%WWeek of the year, Monday as the first day (00–53). Days before the first Monday are week 0.24
%VISO 8601 week number (01–53). Use with %G and %u.25

Locale

%cLocale’s appropriate date and time representation.Jun 18, 2026, 1:45:30 PM
%xLocale’s appropriate date representation.6/18/26
%XLocale’s appropriate time representation.1:45:30 PM

Literal

%%A literal “%” character.%
Names for months, weekdays and AM/PM depend on the active locale; %z and %Z are empty for naive datetimes. The same directives are used by strptime to parse strings back into dates.